Skip to content

Commit a8ca989

Browse files
committed
[PreCheckExpr] Allow pack references when resolving types during TypeExpr folding.
1 parent 5fe47bf commit a8ca989

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/Sema/PreCheckExpr.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1435,8 +1435,13 @@ TypeExpr *PreCheckExpression::simplifyNestedTypeExpr(UnresolvedDotExpr *UDE) {
14351435
// Fold 'T.U' into a nested type.
14361436

14371437
// Resolve the TypeRepr to get the base type for the lookup.
1438+
TypeResolutionOptions options(TypeResolverContext::InExpression);
1439+
// Pre-check always allows pack references during TypeExpr folding.
1440+
// CSGen will diagnose cases that appear outside of pack expansion
1441+
// expressions.
1442+
options |= TypeResolutionFlags::AllowPackReferences;
14381443
const auto BaseTy = TypeResolution::resolveContextualType(
1439-
InnerTypeRepr, DC, TypeResolverContext::InExpression,
1444+
InnerTypeRepr, DC, options,
14401445
[](auto unboundTy) {
14411446
// FIXME: Don't let unbound generic types escape type resolution.
14421447
// For now, just return the unbound generic type.

test/Constraints/pack-expansion-expressions.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,14 @@ func tupleExpansion<each T, each U>(
105105
_ = zip(repeat each tuple1.element, with: repeat each tuple2.element)
106106
// expected-error@-1 {{global function 'zip(_:with:)' requires the type packs 'U' and 'T' have the same shape}}
107107
}
108+
109+
protocol Generatable {
110+
static func generate() -> Self
111+
}
112+
113+
func generateTuple<each T : Generatable>() -> (repeat each T) {
114+
(each T).generate()
115+
// expected-error@-1 {{pack reference 'T' can only appear in pack expansion or generic requirement}}
116+
117+
return (repeat (each T).generate())
118+
}

0 commit comments

Comments
 (0)