Skip to content

[Sema] Handle non-function type parameters for closure arguments in ambiguity diagnositc #60819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/Sema/ConstraintSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4039,7 +4039,8 @@ static bool diagnoseConflictingGenericArguments(ConstraintSystem &cs,
return fix->getKind() == FixKind::AllowArgumentTypeMismatch ||
fix->getKind() == FixKind::AllowFunctionTypeMismatch ||
fix->getKind() == FixKind::AllowTupleTypeMismatch ||
fix->getKind() == FixKind::GenericArgumentsMismatch;
fix->getKind() == FixKind::GenericArgumentsMismatch ||
fix->getKind() == FixKind::InsertCall;
});
});

Expand Down Expand Up @@ -4515,7 +4516,9 @@ static bool diagnoseContextualFunctionCallGenericAmbiguity(

auto argParamMatch = argMatching->second.parameterBindings[i];
auto param = applyFnType->getParams()[argParamMatch.front()];
auto paramFnType = param.getPlainType()->castTo<FunctionType>();
auto paramFnType = param.getPlainType()->getAs<FunctionType>();
if (!paramFnType)
continue;

if (cs.typeVarOccursInType(resultTypeVar, paramFnType->getResult()))
closureArguments.push_back(closure);
Expand Down
12 changes: 12 additions & 0 deletions test/expr/closure/closures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -751,3 +751,15 @@ public class TestImplicitCaptureOfExplicitCaptureOfSelfInEscapingClosure {
if s == "1" { return () } // expected-error{{cannot convert return expression of type '()' to return type 'Bool'}}
return s.isEmpty
}.filter { $0 }

// https://github.com/apple/swift/issues/60781
func f60781<T>(_ x: T) -> T { x }
func f60781<T>(_ x: T, _ y: T) -> T { x }

func test60781() -> Int {
f60781({ 1 }) // expected-error{{conflicting arguments to generic parameter 'T' ('Int' vs. '() -> Int')}}
}

func test60781_MultiArg() -> Int {
f60781({ 1 }, { 1 }) // expected-error{{conflicting arguments to generic parameter 'T' ('Int' vs. '() -> Int')}}
}