Skip to content

Commit d0e20eb

Browse files
authored
Merge pull request #29209 from xedin/rdar-56221372
[ConstraintSystem] Fix `getArgumentExpr` to check number of tuple ele…
2 parents 9f50719 + d318b5d commit d0e20eb

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3384,8 +3384,12 @@ Expr *constraints::getArgumentExpr(Expr *expr, unsigned index) {
33843384
return PE->getSubExpr();
33853385
}
33863386

3387-
assert(isa<TupleExpr>(argExpr));
3388-
return cast<TupleExpr>(argExpr)->getElement(index);
3387+
if (auto *tuple = dyn_cast<TupleExpr>(argExpr)) {
3388+
return (tuple->getNumElements() > index) ? tuple->getElement(index)
3389+
: nullptr;
3390+
}
3391+
3392+
return nullptr;
33893393
}
33903394

33913395
bool constraints::isAutoClosureArgument(Expr *argExpr) {

test/Constraints/function_builder_diags.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ struct Text : P {
160160
init(_: T) {}
161161
}
162162

163-
struct Label<L> : P where L : P { // expected-note {{'L' declared as parameter to type 'Label'}}
163+
struct Label<L> : P where L : P { // expected-note 2 {{'L' declared as parameter to type 'Label'}}
164164
typealias T = L
165-
init(@Builder _: () -> L) {}
165+
init(@Builder _: () -> L) {} // expected-note {{'init(_:)' declared here}}
166166
}
167167

168168
func test_51167632() -> some P {
@@ -173,6 +173,15 @@ func test_51167632() -> some P {
173173
})
174174
}
175175

176+
func test_56221372() -> some P {
177+
AnyP(G {
178+
Text("hello")
179+
Label() // expected-error {{generic parameter 'L' could not be inferred}}
180+
// expected-error@-1 {{missing argument for parameter #1 in call}}
181+
// expected-note@-2 {{explicitly specify the generic arguments to fix this issue}} {{10-10=<<#L: P#>>}}
182+
})
183+
}
184+
176185
struct SR11440 {
177186
typealias ReturnsTuple<T> = () -> (T, T)
178187
subscript<T, U>(@TupleBuilder x: ReturnsTuple<T>) -> (ReturnsTuple<U>) -> Void { //expected-note {{in call to 'subscript(_:)'}}

0 commit comments

Comments
 (0)