Skip to content

Commit d61d923

Browse files
authored
Merge pull request #38702 from nathawes/account-for-synthesized-args
[Sema][CSSimplify] Account for synthesized args when diagnosing labelling issues in matchCallArgumentsImpl
2 parents 9457406 + 8254445 commit d61d923

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,9 @@ static bool matchCallArgumentsImpl(
786786
unsigned argIdx = 0;
787787
for (const auto &binding : parameterBindings) {
788788
paramToArgMap.push_back(argIdx);
789-
argIdx += binding.size();
789+
// Ignore argument bindings that were synthesized due to missing args.
790+
argIdx += llvm::count_if(
791+
binding, [numArgs](unsigned argIdx) { return argIdx < numArgs; });
790792
}
791793
}
792794

@@ -803,6 +805,10 @@ static bool matchCallArgumentsImpl(
803805
// it should move to (toArgIdx).
804806
const auto fromArgIdx = binding[paramBindIdx];
805807

808+
// Ignore argument bindings that were synthesized due to missing args.
809+
if (fromArgIdx >= numArgs)
810+
continue;
811+
806812
// Does nothing for variadic tail.
807813
if (params[paramIdx].isVariadic() && paramBindIdx > 0) {
808814
assert(args[fromArgIdx].getLabel().empty());

test/Constraints/argument_matching.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,15 +1153,15 @@ func testUnlabeledParameterBindingPosition() {
11531153
// expected-error@-2:22 {{missing argument for parameter 'dd' in call}}
11541154

11551155
f(1, xx: 2, dd: 3)
1156-
// expected-error@-1 {{incorrect argument labels in call (have '_:xx:dd:', expected '_:_:cc:dd:')}}
1156+
// expected-error@-1 {{extraneous argument label 'xx:' in call}}
11571157
// expected-error@-2:15 {{missing argument for parameter 'cc' in call}}
11581158

11591159
f(xx: 1, 2, cc: 3)
11601160
// expected-error@-1 {{extraneous argument label 'xx:' in call}}
11611161
// expected-error@-2:22 {{missing argument for parameter 'dd' in call}}
11621162

11631163
f(xx: 1, 2, dd: 3)
1164-
// expected-error@-1 {{incorrect argument labels in call (have 'xx:_:dd:', expected '_:_:cc:dd:')}}
1164+
// expected-error@-1 {{extraneous argument label 'xx:' in call}}
11651165
// expected-error@-2:15 {{missing argument for parameter 'cc' in call}}
11661166

11671167
f(1, xx: 2, cc: 3, dd: 4)
@@ -1207,23 +1207,26 @@ func testUnlabeledParameterBindingPosition() {
12071207

12081208
f(1, xx: 2)
12091209
// expected-error@-1:6 {{missing arguments for parameters 'aa', 'bb' in call}}
1210-
// expected-error@-2 {{incorrect argument labels in call (have '_:xx:', expected 'aa:bb:_:_:')}}
1210+
// expected-error@-2 {{extraneous argument label 'xx:' in call}}
12111211

12121212
f(xx: 1, 2)
1213-
// expected-error@-1 {{incorrect argument labels in call (have 'xx:_:', expected 'aa:bb:_:_:')}}
1213+
// expected-error@-1 {{extraneous argument label 'xx:' in call}}
12141214
// expected-error@-2:6 {{missing arguments for parameters 'aa', 'bb' in call}}
12151215

12161216
f(bb: 1, 2, xx: 3)
12171217
// expected-error@-1:7 {{missing argument for parameter 'aa' in call}}
1218+
// expected-error@-2:6 {{extraneous argument label 'xx:' in call}}
12181219

12191220
f(bb: 1, xx: 2, 3)
12201221
// expected-error@-1:7 {{missing argument for parameter 'aa' in call}}
1222+
// expected-error@-2:6 {{extraneous argument label 'xx:' in call}}
12211223

12221224
f(aa: 1, 2, xx: 3)
12231225
// expected-error@-1:12 {{missing argument for parameter 'bb' in call}}
1226+
// expected-error@-2:6 {{extraneous argument label 'xx:' in call}}
12241227

12251228
f(aa: 1, xx: 2, 3)
1226-
// expected-error@-1 {{incorrect argument labels in call (have 'aa:xx:_:', expected 'aa:bb:_:_:')}}
1229+
// expected-error@-1 {{extraneous argument label 'xx:' in call}}
12271230
// expected-error@-2:12 {{missing argument for parameter 'bb' in call}}
12281231

12291232
f(aa: 1, bb: 2, 3, xx: 4)
@@ -1639,7 +1642,7 @@ _ = CurriedClass.method3(1, 2) // expected-error {{instance member 'me
16391642
// expected-error@-1 {{missing argument label 'b:' in call}}
16401643
CurriedClass.method3(c)(1.0, b: 1) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
16411644
CurriedClass.method3(c)(1) // expected-error {{missing argument for parameter 'b' in call}}
1642-
CurriedClass.method3(c)(c: 1.0) // expected-error {{incorrect argument labels in call (have 'c:', expected '_:b:')}}
1645+
CurriedClass.method3(c)(c: 1.0) // expected-error {{incorrect argument label in call (have 'c:', expected 'b:')}}
16431646
// expected-error@-1 {{cannot convert value of type 'Double' to expected argument type 'Int'}}
16441647
// expected-error@-2 {{missing argument for parameter #1 in call}}
16451648

0 commit comments

Comments
 (0)