Skip to content

Commit 8506d9d

Browse files
authored
Merge pull request #42022 from hborla/default-argument-fixes
[ConstraintSystem] Only attempt to infer a type from a default argument if there is a non-null callee.
2 parents 436c7f2 + 0fdb9a3 commit 8506d9d

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,15 +1768,17 @@ static ConstraintSystem::TypeMatchResult matchCallArguments(
17681768
// If type inference from default arguments is enabled, let's
17691769
// add a constraint from the parameter if necessary, otherwise
17701770
// there is nothing to do but move to the next parameter.
1771-
if (parameterBindings[paramIdx].empty()) {
1771+
if (parameterBindings[paramIdx].empty() && callee) {
17721772
auto &ctx = cs.getASTContext();
17731773

17741774
if (ctx.TypeCheckerOpts.EnableTypeInferenceFromDefaultArguments) {
17751775
auto *paramList = getParameterList(callee);
1776-
auto *PD = paramList->get(paramIdx);
1776+
if (!paramList)
1777+
continue;
17771778

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

test/decl/func/vararg.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-typecheck-verify-swift
2+
// RUN: %target-typecheck-verify-swift -enable-experimental-type-inference-from-defaults
23

34
var t1a: (Int...) = (1)
45
// expected-error@-1 {{cannot create a variadic tuple}}

test/expr/closure/basic.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-typecheck-verify-swift
2+
// RUN: %target-typecheck-verify-swift -enable-experimental-type-inference-from-defaults
23

34
func takeIntToInt(_ f: (Int) -> Int) { }
45
func takeIntIntToInt(_ f: (Int, Int) -> Int) { }

0 commit comments

Comments
 (0)