Skip to content

Commit e2096ae

Browse files
committed
[CSDiagnostics] Tweak candidate note text for arg mismatch
Number the parameters starting at 1 in order to match other diagnostics such as diag::missing_argument_positional, and change the text to make it explicit that we're referring to the parameter position (rather than argument position).
1 parent f03d210 commit e2096ae

File tree

9 files changed

+15
-19
lines changed

9 files changed

+15
-19
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ ERROR(cannot_convert_argument_value,none,
381381
(Type,Type))
382382

383383
NOTE(candidate_has_invalid_argument_at_position,none,
384-
"candidate expects value of type %0 at position #%1",
384+
"candidate expects value of type %0 for parameter #%1",
385385
(Type, unsigned))
386386

387387
ERROR(cannot_convert_array_to_variadic,none,

lib/Sema/CSDiagnostics.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5042,13 +5042,9 @@ bool ArgumentMismatchFailure::diagnoseAsError() {
50425042
}
50435043

50445044
bool ArgumentMismatchFailure::diagnoseAsNote() {
5045-
auto *locator = getLocator();
5046-
auto argToParam = locator->findFirst<LocatorPathElt::ApplyArgToParam>();
5047-
assert(argToParam);
5048-
50495045
if (auto *callee = getCallee()) {
50505046
emitDiagnostic(callee, diag::candidate_has_invalid_argument_at_position,
5051-
getToType(), argToParam->getParamIdx());
5047+
getToType(), getParamPosition());
50525048
return true;
50535049
}
50545050

test/Constraints/closures.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ takeVoidVoidFn { () -> Void in
349349
}
350350

351351
// <rdar://problem/19997471> Swift: Incorrect compile error when calling a function inside a closure
352-
func f19997471(_ x: String) {} // expected-note {{candidate expects value of type 'String' at position #0}}
353-
func f19997471(_ x: Int) {} // expected-note {{candidate expects value of type 'Int' at position #0}}
352+
func f19997471(_ x: String) {} // expected-note {{candidate expects value of type 'String' for parameter #1}}
353+
func f19997471(_ x: Int) {} // expected-note {{candidate expects value of type 'Int' for parameter #1}}
354354

355355
func someGeneric19997471<T>(_ x: T) {
356356
takeVoidVoidFn {

test/Constraints/construction.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ enum Z {
1616

1717
init() { self = .none }
1818
init(_ c: UnicodeScalar) { self = .char(c) }
19-
// expected-note@-1 2 {{candidate expects value of type 'UnicodeScalar' (aka 'Unicode.Scalar') at position #0}}
19+
// expected-note@-1 2 {{candidate expects value of type 'UnicodeScalar' (aka 'Unicode.Scalar') for parameter #1}}
2020
init(_ s: String) { self = .string(s) }
21-
// expected-note@-1 2 {{candidate expects value of type 'String' at position #0}}
21+
// expected-note@-1 2 {{candidate expects value of type 'String' for parameter #1}}
2222
init(_ x: Int, _ y: Int) { self = .point(x, y) }
2323
}
2424

test/Constraints/diagnostics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ func SR_6272_c() {
10691069
struct SR_6272_D: ExpressibleByIntegerLiteral {
10701070
typealias IntegerLiteralType = Int
10711071
init(integerLiteral: Int) {}
1072-
static func +(lhs: SR_6272_D, rhs: Int) -> Float { return 42.0 } // expected-note 2 {{candidate expects value of type 'Int' at position #1}}
1072+
static func +(lhs: SR_6272_D, rhs: Int) -> Float { return 42.0 } // expected-note 2 {{candidate expects value of type 'Int' for parameter #2}}
10731073
}
10741074

10751075
func SR_6272_d() {

test/Constraints/overload.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
func markUsed<T>(_ t: T) {}
44

55
func f0(_: Float) -> Float {}
6-
// expected-note@-1 {{candidate expects value of type 'Float' at position #0}}
6+
// expected-note@-1 {{candidate expects value of type 'Float' for parameter #1}}
77
func f0(_: Int) -> Int {}
8-
// expected-note@-1 {{candidate expects value of type 'Int' at position #0}}
8+
// expected-note@-1 {{candidate expects value of type 'Int' for parameter #1}}
99

1010
func f1(_: Int) {}
1111

test/Generics/function_defs.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ protocol Overload {
7474
associatedtype B
7575
func getA() -> A
7676
func getB() -> B
77-
func f1(_: A) -> A // expected-note {{candidate expects value of type 'OtherOvl.A' at position #0}}
78-
func f1(_: B) -> B // expected-note {{candidate expects value of type 'OtherOvl.B' at position #0}}
77+
func f1(_: A) -> A // expected-note {{candidate expects value of type 'OtherOvl.A' for parameter #1}}
78+
func f1(_: B) -> B // expected-note {{candidate expects value of type 'OtherOvl.B' for parameter #1}}
7979
func f2(_: Int) -> A // expected-note{{found this candidate}}
8080
func f2(_: Int) -> B // expected-note{{found this candidate}}
8181
func f3(_: Int) -> Int // expected-note {{found this candidate}}

test/decl/subscript/subscripting.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,9 @@ func testSubscript1(_ s1 : SubscriptTest1) {
393393
}
394394

395395
struct SubscriptTest2 {
396-
subscript(a : String, b : Int) -> Int { return 0 } // expected-note {{candidate expects value of type 'Int' at position #1}}
396+
subscript(a : String, b : Int) -> Int { return 0 } // expected-note {{candidate expects value of type 'Int' for parameter #2}}
397397
// expected-note@-1 {{declared here}}
398-
subscript(a : String, b : String) -> Int { return 0 } // expected-note {{candidate expects value of type 'String' at position #1}}
398+
subscript(a : String, b : String) -> Int { return 0 } // expected-note {{candidate expects value of type 'String' for parameter #2}}
399399
}
400400

401401
func testSubscript1(_ s2 : SubscriptTest2) {

validation-test/compiler_crashers_2_fixed/0146-rdar38309176.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %target-typecheck-verify-swift
22

3-
func foo(_ msg: Int) {} // expected-note {{candidate expects value of type 'Int' at position #0}}
4-
func foo(_ msg: Double) {} // expected-note {{candidate expects value of type 'Double' at position #0}}
3+
func foo(_ msg: Int) {} // expected-note {{candidate expects value of type 'Int' for parameter #1}}
4+
func foo(_ msg: Double) {} // expected-note {{candidate expects value of type 'Double' for parameter #1}}
55

66
func rdar38309176(_ errors: inout [String]) {
77
foo("error: \(errors[0])") // expected-error {{no exact matches in call to global function 'foo'}}

0 commit comments

Comments
 (0)