Skip to content

Commit 34b720c

Browse files
committed
[CSGen] Constraint generation for PackExpansionExpr should return a null type
if the constraint system has not recorded a type for an expanded pack element type repr.
1 parent a8ca989 commit 34b720c

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lib/Sema/CSGen.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3078,6 +3078,12 @@ namespace {
30783078
if (auto *elementExpr = getAsExpr<PackElementExpr>(pack)) {
30793079
packType = CS.getType(elementExpr->getPackRefExpr());
30803080
} else if (auto *elementType = getAsTypeRepr<PackElementTypeRepr>(pack)) {
3081+
// OpenPackElementType sets types for 'each T' type reprs in
3082+
// expressions. Some invalid code won't make it there, and
3083+
// the constraint system won't have recorded a type.
3084+
if (!CS.hasType(elementType->getPackType()))
3085+
return Type();
3086+
30813087
packType = CS.getType(elementType->getPackType());
30823088
} else {
30833089
llvm_unreachable("unsupported pack reference ASTNode");

test/Constraints/pack-expansion-expressions.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func typeReprPacks<each T>(_ t: repeat each T) where each T: ExpressibleByIntege
7070

7171
_ = Array<each T>() // expected-error {{pack reference 'T' can only appear in pack expansion or generic requirement}}
7272
_ = 1 as each T // expected-error {{pack reference 'T' can only appear in pack expansion or generic requirement}}
73+
repeat Invalid<String, each T>("") // expected-error {{cannot find 'Invalid' in scope}}
7374
}
7475

7576
func sameShapeDiagnostics<each T, each U>(t: repeat each T, u: repeat each U) {

0 commit comments

Comments
 (0)