Skip to content

Commit 17ec1ac

Browse files
committed
[Sema] Improve diagnostic message for out of order arguments
* Argument numbers are 1 based, not starting from 0. * Use the term `argument` consistently, `parameter` is not a term for call site.
1 parent d9d5829 commit 17ec1ac

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -762,11 +762,11 @@ ERROR(extra_named_single_element_tuple,none,
762762
ERROR(argument_out_of_order_named_named,none,
763763
"argument %0 must precede argument %1", (Identifier, Identifier))
764764
ERROR(argument_out_of_order_named_unnamed,none,
765-
"argument %0 must precede unnamed parameter #%1", (Identifier, unsigned))
765+
"argument %0 must precede unnamed argument #%1", (Identifier, unsigned))
766766
ERROR(argument_out_of_order_unnamed_named,none,
767-
"unnamed parameter #%0 must precede argument %1", (unsigned, Identifier))
767+
"unnamed argument #%0 must precede argument %1", (unsigned, Identifier))
768768
ERROR(argument_out_of_order_unnamed_unnamed,none,
769-
"unnamed parameter #%0 must precede unnamed parameter #%1",
769+
"unnamed argument #%0 must precede unnamed argument #%1",
770770
(unsigned, unsigned))
771771

772772
ERROR(instance_member_use_on_type,none,

lib/Sema/CSDiag.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4255,15 +4255,15 @@ static bool diagnoseSingleCandidateFailures(CalleeCandidateInfo &CCI,
42554255

42564256
if (first.empty() && second.empty()) {
42574257
TC.diagnose(diagLoc, diag::argument_out_of_order_unnamed_unnamed,
4258-
OOOArgIdx, OOOPrevArgIdx)
4258+
OOOArgIdx + 1, OOOPrevArgIdx + 1)
42594259
.fixItExchange(firstRange, secondRange);
42604260
} else if (first.empty() && !second.empty()) {
42614261
TC.diagnose(diagLoc, diag::argument_out_of_order_unnamed_named,
4262-
OOOArgIdx, second)
4262+
OOOArgIdx + 1, second)
42634263
.fixItExchange(firstRange, secondRange);
42644264
} else if (!first.empty() && second.empty()) {
42654265
TC.diagnose(diagLoc, diag::argument_out_of_order_named_unnamed,
4266-
first, OOOPrevArgIdx)
4266+
first, OOOPrevArgIdx + 1)
42674267
.fixItExchange(firstRange, secondRange);
42684268
} else {
42694269
TC.diagnose(diagLoc, diag::argument_out_of_order_named_named,

test/Constraints/diagnostics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ func nilComparison(i: Int, o: AnyObject) {
801801
// FIXME: Bad diagnostic
802802
func secondArgumentNotLabeled(a:Int, _ b: Int) { }
803803
secondArgumentNotLabeled(10, 20)
804-
// expected-error@-1 {{unnamed parameter #1 must precede unnamed parameter #0}}
804+
// expected-error@-1 {{unnamed argument #2 must precede unnamed argument #1}}
805805

806806
// <rdar://problem/23709100> QoI: incorrect ambiguity error due to implicit conversion
807807
func testImplConversion(a : Float?) -> Bool {}

test/Constraints/function.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ var s: String = optFunc("hi")
3636
// <rdar://problem/17652759> Default arguments cause crash with tuple permutation
3737
func testArgumentShuffle(_ first: Int = 7, third: Int = 9) {
3838
}
39-
testArgumentShuffle(third: 1, 2) // expected-error {{unnamed parameter #1 must precede argument 'third'}} {{21-29=2}} {{31-32=third: 1}}
39+
testArgumentShuffle(third: 1, 2) // expected-error {{unnamed argument #2 must precede argument 'third'}} {{21-29=2}} {{31-32=third: 1}}
4040

4141

4242

test/Constraints/keyword_arguments.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ variadics1(x: 1, y: 2, 1, 2)
135135
variadics1(x: 1, y: 2, 1, 2, 3)
136136

137137
// Using various (out-of-order)
138-
variadics1(1, 2, 3, 4, 5, x: 6, y: 7) // expected-error{{argument 'x' must precede unnamed parameter #0}} {{12-25=x: 6}} {{27-31=1, 2, 3, 4, 5}}
138+
variadics1(1, 2, 3, 4, 5, x: 6, y: 7) // expected-error{{argument 'x' must precede unnamed argument #1}} {{12-25=x: 6}} {{27-31=1, 2, 3, 4, 5}}
139139

140140
func variadics2(x: Int, y: Int = 2, z: Int...) { }
141141

@@ -173,8 +173,8 @@ variadics3(1)
173173
variadics3()
174174

175175
// Using variadics (out-of-order)
176-
variadics3(y: 0, 1, 2, 3) // expected-error{{unnamed parameter #1 must precede argument 'y'}} {{12-16=1, 2, 3}} {{18-25=y: 0}}
177-
variadics3(z: 1, 1) // expected-error{{unnamed parameter #1 must precede argument 'z'}} {{12-16=1}} {{18-19=z: 1}}
176+
variadics3(y: 0, 1, 2, 3) // expected-error{{unnamed argument #2 must precede argument 'y'}} {{12-16=1, 2, 3}} {{18-25=y: 0}}
177+
variadics3(z: 1, 1) // expected-error{{unnamed argument #2 must precede argument 'z'}} {{12-16=1}} {{18-19=z: 1}}
178178

179179
func variadics4(x: Int..., y: Int = 2, z: Int = 3) { }
180180

@@ -209,7 +209,7 @@ variadics5(1, y: 2, 1, 2)
209209
variadics5(1, y: 2, 1, 2, 3)
210210

211211
// Using various (out-of-order)
212-
variadics5(1, 2, 3, 4, 5, 6, y: 7) // expected-error{{argument 'y' must precede unnamed parameter #1}} {{15-28=y: 7}} {{30-34=2, 3, 4, 5, 6}}
212+
variadics5(1, 2, 3, 4, 5, 6, y: 7) // expected-error{{argument 'y' must precede unnamed argument #2}} {{15-28=y: 7}} {{30-34=2, 3, 4, 5, 6}}
213213
variadics5(y: 1, 2, 3, 4, 5, 6, 7) // expected-error{{missing argument for parameter #1 in call}}
214214

215215
func variadics6(x: Int..., y: Int = 2, z: Int) { }
@@ -233,7 +233,7 @@ variadics6(x: 1) // expected-error{{missing argument for parameter 'z' in call}}
233233
variadics6() // expected-error{{missing argument for parameter 'z' in call}}
234234

235235
func outOfOrder(_ a : Int, b: Int) {
236-
outOfOrder(b: 42, 52) // expected-error {{unnamed parameter #1 must precede argument 'b'}} {{14-19=52}} {{21-23=b: 42}}
236+
outOfOrder(b: 42, 52) // expected-error {{unnamed argument #2 must precede argument 'b'}} {{14-19=52}} {{21-23=b: 42}}
237237
}
238238

239239
// -------------------------------------------

0 commit comments

Comments
 (0)