Skip to content

Commit b4c873a

Browse files
authored
Merge pull request #37941 from LucianoPAlmeida/SR-14784-diag
[SR-14784][Sema] Make sure we look through optionals on anchor fnType for MissingCallFailure
2 parents 97ab864 + 33e47c1 commit b4c873a

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3252,7 +3252,8 @@ bool MissingCallFailure::diagnoseAsError() {
32523252
switch (last.getKind()) {
32533253
case ConstraintLocator::ContextualType:
32543254
case ConstraintLocator::ApplyArgToParam: {
3255-
auto fnType = getType(anchor)->castTo<FunctionType>();
3255+
auto type = getType(anchor)->lookThroughAllOptionalTypes();
3256+
auto fnType = type->castTo<FunctionType>();
32563257
emitDiagnostic(diag::missing_nullary_call, fnType->getResult())
32573258
.fixItInsertAfter(insertLoc, "()");
32583259
return true;

test/Constraints/function.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,8 @@ func test_passing_noescape_function_ref_to_generic_parameter() {
245245
}
246246
}
247247
}
248+
249+
// SR-14784
250+
func SR14784<T>(_ fs: () -> T..., a _ : Int) -> T {
251+
fs.first! // expected-error{{function produces expected type 'T'; did you mean to call it with '()'?}} {{11-11=()}}
252+
}

0 commit comments

Comments
 (0)