Skip to content

Commit bb443c6

Browse files
authored
Merge pull request swiftlang#21233 from brentdax/thats-this-diagnostic-sorted
2 parents 2b5db0d + eb81efe commit bb443c6

16 files changed

+41
-40
lines changed

lib/Sema/CalleeCandidateInfo.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -933,8 +933,7 @@ operator=(const CalleeCandidateInfo &CCI) {
933933
/// arguments, emit a diagnostic indicating any partially matching overloads.
934934
void CalleeCandidateInfo::
935935
suggestPotentialOverloads(SourceLoc loc, bool isResult) {
936-
std::string suggestionText = "";
937-
std::set<std::string> dupes;
936+
std::set<std::string> sorted;
938937

939938
// FIXME2: For (T,T) & (Self, Self), emit this as two candidates, one using
940939
// the LHS and one using the RHS type for T's.
@@ -947,18 +946,20 @@ suggestPotentialOverloads(SourceLoc loc, bool isResult) {
947946
// If we've already seen this (e.g. decls overridden on the result type),
948947
// ignore this one.
949948
auto name = isResult ? type->getString() : getTypeListString(type);
950-
if (!dupes.insert(name).second)
951-
continue;
952-
949+
sorted.insert(name);
950+
}
951+
952+
if (sorted.empty())
953+
return;
954+
955+
std::string suggestionText = "";
956+
for (auto name : sorted) {
953957
if (!suggestionText.empty())
954958
suggestionText += ", ";
955959
suggestionText += name;
956960
}
957-
958-
if (suggestionText.empty())
959-
return;
960-
961-
if (dupes.size() == 1) {
961+
962+
if (sorted.size() == 1) {
962963
CS.TC.diagnose(loc, diag::suggest_expected_match, isResult, suggestionText);
963964
} else {
964965
CS.TC.diagnose(loc, diag::suggest_partial_overloads, isResult, declName,

test/ClangImporter/objc_diags.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ import ObjectiveC
44

55
func instanceMethod(_ b: B) {
66
b.method(1, 2.5) // expected-error {{argument labels '(_:, _:)' do not match any available overloads}}
7-
// expected-note @-1 {{overloads for 'method' exist with these partially matching parameter lists: (Int32, with: Float), (Int32, withFloat: Float), (Int32, onExtB: Double), (Int32, with: Double), (Int32, withDouble: Double), (Int32, onExtA: Double), (Int32, onCat1: Double)}}
7+
// expected-note @-1 {{overloads for 'method' exist with these partially matching parameter lists: (Int32, onCat1: Double), (Int32, onExtA: Double), (Int32, onExtB: Double), (Int32, with: Double), (Int32, with: Float), (Int32, withDouble: Double), (Int32, withFloat: Float)}}
88
}

test/ClangImporter/objc_factory_method.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func testInstanceTypeFactoryMethodInherited() {
2424
_ = NSObjectFactorySub(double: 314159)
2525
_ = NSObjectFactorySub(float: 314159) // expected-error{{incorrect argument label in call (have 'float:', expected 'integer:')}}
2626
let a = NSObjectFactorySub(buildingWidgets: ()) // expected-error{{argument labels '(buildingWidgets:)' do not match any available overloads}}
27-
// expected-note @-1 {{overloads for 'NSObjectFactorySub' exist with these partially matching parameter lists: (integer: Int), (double: Double)}}
27+
// expected-note @-1 {{overloads for 'NSObjectFactorySub' exist with these partially matching parameter lists: (double: Double), (integer: Int)}}
2828
_ = a
2929
}
3030

@@ -77,7 +77,7 @@ func testNSErrorFactoryMethod(_ path: String) throws {
7777

7878
func testNonInstanceTypeFactoryMethod(_ s: String) {
7979
_ = NSObjectFactory(string: s) // expected-error{{argument labels '(string:)' do not match any available overloads}}
80-
// expected-note @-1 {{(integer: Int), (double: Double), (float: Float)}}
80+
// expected-note @-1 {{(double: Double), (float: Float), (integer: Int)}}
8181
}
8282

8383
func testUseOfFactoryMethod(_ queen: Bee) {

test/ClangImporter/objc_implicit_with.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func testInstanceTypeFactoryMethodInherited() {
3535
_ = NSObjectFactorySub(double: 314159)
3636
_ = NSObjectFactorySub(float: 314159) // expected-error{{incorrect argument label in call (have 'float:', expected 'integer:')}}
3737
let a = NSObjectFactorySub(buildingWidgets: ()) // expected-error{{argument labels '(buildingWidgets:)' do not match any available overloads}}
38-
// expected-note @-1 {{overloads for 'NSObjectFactorySub' exist with these partially matching parameter lists: (integer: Int), (double: Double)}}
38+
// expected-note @-1 {{overloads for 'NSObjectFactorySub' exist with these partially matching parameter lists: (double: Double), (integer: Int)}}
3939
_ = a
4040
}
4141

@@ -45,7 +45,7 @@ func testNSErrorFactoryMethod(_ path: String) throws {
4545

4646
func testNonInstanceTypeFactoryMethod(_ s: String) {
4747
_ = NSObjectFactory(string: s) // expected-error{{argument labels '(string:)' do not match any available overloads}}
48-
// expected-note @-1 {{overloads for 'NSObjectFactory' exist with these partially matching parameter lists: (integer: Int), (double: Double), (float: Float)}}
48+
// expected-note @-1 {{overloads for 'NSObjectFactory' exist with these partially matching parameter lists: (double: Double), (float: Float), (integer: Int)}}
4949
}
5050

5151
func testUseOfFactoryMethod(_ queen: Bee) {

test/Constraints/bridging.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ func rdar19831698() {
269269
var v72 = true + true // expected-error{{binary operator '+' cannot be applied to two 'Bool' operands}}
270270
// expected-note @-1 {{overloads for '+' exist with these partially matching parameter lists:}}
271271
var v73 = true + [] // expected-error{{binary operator '+' cannot be applied to operands of type 'Bool' and '[Any]'}}
272-
// expected-note @-1 {{overloads for '+' exist with these partially matching parameter lists: (Array<Element>, Array<Element>), (Self, Other), (Other, Self)}}
272+
// expected-note @-1 {{overloads for '+' exist with these partially matching parameter lists: (Array<Element>, Array<Element>), (Other, Self), (Self, Other)}}
273273
var v75 = true + "str" // expected-error {{binary operator '+' cannot be applied to operands of type 'Bool' and 'String'}} expected-note {{expected an argument list of type '(String, String)'}}
274274
}
275275

test/Constraints/closures.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ func f19997471(_ x: Int) {}
356356
func someGeneric19997471<T>(_ x: T) {
357357
takeVoidVoidFn {
358358
f19997471(x) // expected-error {{cannot invoke 'f19997471' with an argument list of type '(T)'}}
359-
// expected-note @-1 {{overloads for 'f19997471' exist with these partially matching parameter lists: (String), (Int)}}
359+
// expected-note @-1 {{overloads for 'f19997471' exist with these partially matching parameter lists: (Int), (String)}}
360360
}
361361
}
362362

@@ -747,7 +747,7 @@ takesTwoInOut { _ in } // expected-error {{contextual closure type '(Int, inout
747747
func f20371273() {
748748
let x: [Int] = [1, 2, 3, 4]
749749
let y: UInt = 4
750-
_ = x.filter { ($0 + y) > 42 } // expected-error {{binary operator '+' cannot be applied to operands of type 'Int' and 'UInt'}} expected-note {{overloads for '+' exist with these partially matching parameter lists: (UInt, UInt), (Int, Int)}}
750+
_ = x.filter { ($0 + y) > 42 } // expected-error {{binary operator '+' cannot be applied to operands of type 'Int' and 'UInt'}} expected-note {{overloads for '+' exist with these partially matching parameter lists: (Int, Int), (UInt, UInt)}}
751751
}
752752

753753
// rdar://problem/42337247

test/Constraints/construction.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ _ = b as! Derived
9494
Int(i) // expected-warning{{unused}}
9595
_ = i as Int
9696
Z(z) // expected-error{{cannot invoke initializer for type 'Z' with an argument list of type '(Z)'}}
97-
// expected-note @-1 {{overloads for 'Z' exist with these partially matching parameter lists: (UnicodeScalar), (String)}}
97+
// expected-note @-1 {{overloads for 'Z' exist with these partially matching parameter lists: (String), (UnicodeScalar)}}
9898

9999
Z.init(z) // expected-error {{cannot invoke 'Z.Type.init' with an argument list of type '(Z)'}}
100-
// expected-note @-1 {{overloads for 'Z.Type.init' exist with these partially matching parameter lists: (UnicodeScalar), (String)}}
100+
// expected-note @-1 {{overloads for 'Z.Type.init' exist with these partially matching parameter lists: (String), (UnicodeScalar)}}
101101

102102

103103
_ = z as Z

test/Constraints/diagnostics.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ example21890157.property = "confusing" // expected-error {{value of optional ty
659659
struct UnaryOp {}
660660

661661
_ = -UnaryOp() // expected-error {{unary operator '-' cannot be applied to an operand of type 'UnaryOp'}}
662-
// expected-note@-1 {{overloads for '-' exist with these partially matching parameter lists: (Float), (Double)}}
662+
// expected-note@-1 {{overloads for '-' exist with these partially matching parameter lists: (Double), (Float), (Float80)}}
663663

664664

665665
// <rdar://problem/23433271> Swift compiler segfault in failure diagnosis
@@ -708,10 +708,10 @@ if AssocTest.one(1) == AssocTest.one(1) {} // expected-error{{binary operator '=
708708
func r24251022() {
709709
var a = 1
710710
var b: UInt32 = 2
711-
_ = a + b // expected-error {{binary operator '+' cannot be applied to operands of type 'Int' and 'UInt32'}} expected-note {{overloads for '+' exist with these partially matching parameter lists: (UInt32, UInt32), (Int, Int)}}
711+
_ = a + b // expected-error {{binary operator '+' cannot be applied to operands of type 'Int' and 'UInt32'}} expected-note {{overloads for '+' exist with these partially matching parameter lists: (Int, Int), (UInt32, UInt32)}}
712712
a += a + // expected-error {{binary operator '+' cannot be applied to operands of type 'Int' and 'UInt32'}} expected-note {{overloads for '+' exist with these partially matching parameter lists:}}
713713
b
714-
a += b // expected-error {{binary operator '+=' cannot be applied to operands of type 'Int' and 'UInt32'}} expected-note {{overloads for '+=' exist with these partially matching parameter lists: (inout UInt32, UInt32), (inout Int, Int)}}
714+
a += b // expected-error {{binary operator '+=' cannot be applied to operands of type 'Int' and 'UInt32'}} expected-note {{overloads for '+=' exist with these partially matching parameter lists: (inout Int, Int), (inout UInt32, UInt32)}}
715715
}
716716

717717
func overloadSetResultType(_ a : Int, b : Int) -> Int {
@@ -1005,15 +1005,15 @@ func SR_6272_d() {
10051005
let x: Float = 1.0
10061006

10071007
// expected-error@+2 {{binary operator '+' cannot be applied to operands of type 'SR_6272_D' and 'Float'}} {{none}}
1008-
// expected-note@+1 {{overloads for '+' exist with these partially matching parameter lists: (SR_6272_D, Int), (Float, Float)}}
1008+
// expected-note@+1 {{overloads for '+' exist with these partially matching parameter lists: (Float, Float), (SR_6272_D, Int)}}
10091009
let _: Float = SR_6272_D(integerLiteral: 42) + x
10101010

10111011
// expected-error@+2 {{binary operator '+' cannot be applied to operands of type 'SR_6272_D' and 'Double'}} {{none}}
1012-
// expected-note@+1 {{overloads for '+' exist with these partially matching parameter lists: (SR_6272_D, Int), (Double, Double)}}
1012+
// expected-note@+1 {{overloads for '+' exist with these partially matching parameter lists: (Double, Double), (SR_6272_D, Int)}}
10131013
let _: Float = SR_6272_D(integerLiteral: 42) + 42.0
10141014

10151015
// expected-error@+2 {{binary operator '+' cannot be applied to operands of type 'SR_6272_D' and 'Float'}} {{none}}
1016-
// expected-note@+1 {{overloads for '+' exist with these partially matching parameter lists: (SR_6272_D, Int), (Float, Float)}}
1016+
// expected-note@+1 {{overloads for '+' exist with these partially matching parameter lists: (Float, Float), (SR_6272_D, Int)}}
10171017
let _: Float = SR_6272_D(integerLiteral: 42) + x + 1.0
10181018
}
10191019

test/Constraints/overload.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func overloaded_identity(_ b : Float) -> Float {}
131131

132132
func test_contextual_result_1() {
133133
return overloaded_identity() // expected-error {{cannot invoke 'overloaded_identity' with no arguments}}
134-
// expected-note @-1 {{overloads for 'overloaded_identity' exist with these partially matching parameter lists: (Int), (Float)}}
134+
// expected-note @-1 {{overloads for 'overloaded_identity' exist with these partially matching parameter lists: (Float), (Int)}}
135135
}
136136

137137
func test_contextual_result_2() {

test/Constraints/super_constructor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class D : B {
2121

2222
init(g:Int) {
2323
super.init("aoeu") // expected-error{{argument labels '(_:)' do not match any available overloads}}
24-
// expected-note @-1 {{overloads for 'B.init' exist with these partially matching parameter lists: (x: Int), (a: UnicodeScalar), (b: UnicodeScalar), (z: Float)}}
24+
// expected-note @-1 {{overloads for 'B.init' exist with these partially matching parameter lists: (a: UnicodeScalar), (b: UnicodeScalar), (x: Int), (z: Float)}}
2525
}
2626

2727
init(h:Int) {

0 commit comments

Comments
 (0)