Skip to content

[ConstraintSystem] Only attempt to infer a type from a default argument if there is a non-null callee. #42022

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 2 commits into from
Mar 25, 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
6 changes: 4 additions & 2 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1748,15 +1748,17 @@ static ConstraintSystem::TypeMatchResult matchCallArguments(
// If type inference from default arguments is enabled, let's
// add a constraint from the parameter if necessary, otherwise
// there is nothing to do but move to the next parameter.
if (parameterBindings[paramIdx].empty()) {
if (parameterBindings[paramIdx].empty() && callee) {
auto &ctx = cs.getASTContext();

if (ctx.TypeCheckerOpts.EnableTypeInferenceFromDefaultArguments) {
auto *paramList = getParameterList(callee);
auto *PD = paramList->get(paramIdx);
if (!paramList)
continue;

// There is nothing to infer if parameter doesn't have any
// generic parameters in its type.
auto *PD = paramList->get(paramIdx);
if (!PD->getInterfaceType()->hasTypeParameter())
continue;

Expand Down
1 change: 1 addition & 0 deletions test/decl/func/vararg.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: %target-typecheck-verify-swift
// RUN: %target-typecheck-verify-swift -enable-experimental-type-inference-from-defaults

var t1a: (Int...) = (1)
// expected-error@-1 {{cannot create a variadic tuple}}
Expand Down
1 change: 1 addition & 0 deletions test/expr/closure/basic.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: %target-typecheck-verify-swift
// RUN: %target-typecheck-verify-swift -enable-experimental-type-inference-from-defaults

func takeIntToInt(_ f: (Int) -> Int) { }
func takeIntIntToInt(_ f: (Int, Int) -> Int) { }
Expand Down