Skip to content

Commit 8e8f081

Browse files
[Sema] Inncrease the score a bit higher for argument mismatch and updating tests
1 parent c09af51 commit 8e8f081

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9824,9 +9824,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
98249824
}
98259825

98269826
case FixKind::AllowArgumentTypeMismatch: {
9827-
increaseScore(SK_Fix);
9828-
9829-
auto impact = 1;
9827+
auto impact = 2;
98309828
// If there are any other argument mismatches already detected for this
98319829
// call, we increase the score even higher so more argument fixes means
98329830
// less viable is the overload.
@@ -9836,7 +9834,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
98369834
? fixLocator->getAnchor() == locator.getAnchor()
98379835
: false;
98389836
}))
9839-
impact = 2;
9837+
impact += 3;
98409838

98419839
return recordFix(fix, impact) ? SolutionKind::Error : SolutionKind::Solved;
98429840
}

test/Constraints/diagnostics.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,14 +1101,16 @@ func rdar17170728() {
11011101
// expected-error@-1 4 {{optional type 'Int?' cannot be used as a boolean; test for '!= nil' instead}}
11021102
}
11031103

1104+
// expected-error@+4 {{value of optional type 'Int?' must be unwrapped to a value of type 'Int'}}
1105+
// expected-error@+3 {{missing argument label 'into:' in call}}
1106+
// expected-note@+2 {{coalesce using '??' to provide a default when the optional value contains 'nil'}}
1107+
// expected-note@+1 {{force-unwrap using '!' to abort execution if the optional value contains 'nil'}}
11041108
let _ = [i, j, k].reduce(0 as Int?) {
1105-
// expected-error@-1 3 {{cannot convert value of type 'Int?' to expected element type 'Int'}}
1109+
// expected-error@-1 3 {{cannot convert value of type 'Int?' to expected element type 'Bool'}}
11061110
$0 && $1 ? $0 + $1 : ($0 ? $0 : ($1 ? $1 : nil))
11071111
// expected-error@-1 2 {{type 'Int' cannot be used as a boolean; test for '!= 0' instead}}
1108-
// expected-error@-2 {{value of optional type 'Int?' must be unwrapped to a value of type 'Int'}}
1109-
// expected-error@-3 2 {{optional type 'Int?' cannot be used as a boolean; test for '!= nil' instead}}
1110-
// expected-note@-4:16 {{coalesce using '??' to provide a default when the optional value contains 'nil'}}
1111-
// expected-note@-5:16 {{force-unwrap using '!' to abort execution if the optional value contains 'nil'}}
1112+
// expected-error@-2 {{cannot convert value of type 'Bool' to expected argument type 'Int'}}
1113+
// expected-error@-3 {{result values in '? :' expression have mismatching types 'Bool' and 'Int?'}}
11121114
}
11131115
}
11141116

test/Parse/type_expr.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ protocol P3 {}
266266
func compositionType() {
267267
_ = P1 & P2 // expected-error {{expected member name or constructor call after type name}} expected-note{{use '.self'}} {{7-7=(}} {{14-14=).self}}
268268
_ = P1 & P2.self // expected-error {{binary operator '&' cannot be applied to operands of type 'P1.Protocol' and 'P2.Protocol'}}
269-
// expected-note@-1 {{overloads for '&' exist with these partially matching parameter lists: (Int, Int), (Int16, Int16), (Int32, Int32), (Int64, Int64), (Int8, Int8), (UInt, UInt), (UInt16, UInt16), (UInt32, UInt32), (UInt64, UInt64), (UInt8, UInt8)}}
270269
_ = (P1 & P2).self // Ok.
271270
_ = (P1 & (P2)).self // FIXME: OK? while `typealias P = P1 & (P2)` is rejected.
272271
_ = (P1 & (P2, P3)).self // expected-error {{non-protocol, non-class type '(P2, P3)' cannot be used within a protocol-constrained type}}

0 commit comments

Comments
 (0)