Skip to content

Commit 1097375

Browse files
[Sema] Handle non-function type parameters for closure arguments in ambiguity diagnositc
1 parent 6fe9dd3 commit 1097375

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4039,7 +4039,8 @@ static bool diagnoseConflictingGenericArguments(ConstraintSystem &cs,
40394039
return fix->getKind() == FixKind::AllowArgumentTypeMismatch ||
40404040
fix->getKind() == FixKind::AllowFunctionTypeMismatch ||
40414041
fix->getKind() == FixKind::AllowTupleTypeMismatch ||
4042-
fix->getKind() == FixKind::GenericArgumentsMismatch;
4042+
fix->getKind() == FixKind::GenericArgumentsMismatch ||
4043+
fix->getKind() == FixKind::InsertCall;
40434044
});
40444045
});
40454046

@@ -4515,7 +4516,9 @@ static bool diagnoseContextualFunctionCallGenericAmbiguity(
45154516

45164517
auto argParamMatch = argMatching->second.parameterBindings[i];
45174518
auto param = applyFnType->getParams()[argParamMatch.front()];
4518-
auto paramFnType = param.getPlainType()->castTo<FunctionType>();
4519+
auto paramFnType = param.getPlainType()->getAs<FunctionType>();
4520+
if (!paramFnType)
4521+
continue;
45194522

45204523
if (cs.typeVarOccursInType(resultTypeVar, paramFnType->getResult()))
45214524
closureArguments.push_back(closure);

test/expr/closure/closures.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,3 +751,15 @@ public class TestImplicitCaptureOfExplicitCaptureOfSelfInEscapingClosure {
751751
if s == "1" { return () } // expected-error{{cannot convert return expression of type '()' to return type 'Bool'}}
752752
return s.isEmpty
753753
}.filter { $0 }
754+
755+
// https://github.com/apple/swift/issues/60781
756+
func f60781<T>(_ x: T) -> T { x }
757+
func f60781<T>(_ x: T, _ y: T) -> T { x }
758+
759+
func test60781() -> Int {
760+
f60781({ 1 }) // expected-error{{conflicting arguments to generic parameter 'T' ('Int' vs. '() -> Int')}}
761+
}
762+
763+
func test60781_MultiArg() -> Int {
764+
f60781({ 1 }, { 1 }) // expected-error{{conflicting arguments to generic parameter 'T' ('Int' vs. '() -> Int')}}
765+
}

0 commit comments

Comments
 (0)