Skip to content

Commit ac2305e

Browse files
committed
[ConstraintSystem] Increase impact of fixes for some conditional requirements
If there is a conditional requirement failure associated with member/function reference used in a call let's increase a score of a fix for such failure because it renders member/function unreachable in current context or with a given set of arguments.
1 parent 7641d9c commit ac2305e

File tree

6 files changed

+20
-6
lines changed

6 files changed

+20
-6
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,6 +1449,20 @@ assessRequirementFailureImpact(ConstraintSystem &cs, Type requirementType,
14491449
if (!anchor)
14501450
return impact;
14511451

1452+
// If this is a conditional requirement failure associated with a
1453+
// call, let's increase impact of the fix to show that such failure
1454+
// makes member/function unreachable in current context or with
1455+
// given arguments.
1456+
if (auto last = locator.last()) {
1457+
if (last->isConditionalRequirement()) {
1458+
if (auto *expr = getAsExpr(anchor)) {
1459+
auto *parent = cs.getParentExpr(expr);
1460+
if (parent && isa<ApplyExpr>(parent))
1461+
return 5;
1462+
}
1463+
}
1464+
}
1465+
14521466
// If this requirement is associated with a member reference and it
14531467
// was possible to check it before overload choice is bound, that means
14541468
// types came from the context (most likely Self, or associated type(s))

test/Constraints/bridging.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func dictionaryToNSDictionary() {
180180
// In this case, we should not implicitly convert Dictionary to NSDictionary.
181181
struct NotEquatable {}
182182
func notEquatableError(_ d: Dictionary<Int, NotEquatable>) -> Bool {
183-
return d == d // expected-error{{operator function '==' requires that 'NotEquatable' conform to 'Equatable'}}
183+
return d == d // expected-error{{referencing operator function '==' on 'Dictionary' requires that 'NotEquatable' conform to 'Equatable'}}
184184
}
185185

186186
// NSString -> String

test/Constraints/operator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func rdar46459603() {
220220
// expected-error@-1 {{referencing operator function '==' on 'Equatable' requires that 'Dictionary<String, E>.Values' conform to 'Equatable'}}
221221
// expected-error@-2 {{cannot convert value of type '[E]' to expected argument type 'Dictionary<String, E>.Values'}}
222222
_ = [arr.values] == [[e]]
223-
// expected-error@-1 {{operator function '==' requires that 'Dictionary<String, E>.Values' conform to 'Equatable'}}
223+
// expected-error@-1 {{referencing operator function '==' on 'Array' requires that 'Dictionary<String, E>.Values' conform to 'Equatable'}}
224224
// expected-error@-2 {{cannot convert value of type '[E]' to expected element type 'Dictionary<String, E>.Values'}}
225225
}
226226

test/Generics/conditional_conformances.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,9 @@ extension Foo: P where Bar: P {
413413
extension BinaryInteger {
414414
var foo: Self {
415415
return self <= 1
416-
? 1
416+
? 1 // expected-error {{cannot convert return expression of type 'Int' to return type 'Self'}}
417417
: (2...self).reduce(1, *)
418-
// expected-error@-1 {{referencing instance method 'reduce' on 'ClosedRange' requires that 'Self.Stride' conform to 'SignedInteger'}}
418+
// expected-error@-1 {{cannot convert value of type 'Self' to expected argument type 'Int'}} {{20-20=Int(}} {{24-24=)}}
419419
}
420420
}
421421

test/Parse/pointer_conversion.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ struct NotEquatable {}
307307
func arrayComparison(_ x: [NotEquatable], y: [NotEquatable], p: UnsafeMutablePointer<NotEquatable>) {
308308
var x = x
309309
// Don't allow implicit array-to-pointer conversions in operators.
310-
let a: Bool = x == y // expected-error{{operator function '==' requires that 'NotEquatable' conform to 'Equatable'}}
310+
let a: Bool = x == y // expected-error{{referencing operator function '==' on 'Array' requires that 'NotEquatable' conform to 'Equatable'}}
311311
let _: Bool = p == &x // Allowed!
312312
}
313313

test/stdlib/ArrayDiagnostics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ class NotEquatable {}
44

55
func test_ArrayOfNotEquatableIsNotEquatable() {
66
var a = [ NotEquatable(), NotEquatable() ]
7-
if a == a {} // expected-error {{operator function '==' requires that 'NotEquatable' conform to 'Equatable'}}
7+
if a == a {} // expected-error {{referencing operator function '==' on 'Array' requires that 'NotEquatable' conform to 'Equatable'}}
88
}

0 commit comments

Comments
 (0)