Skip to content

Commit 2d10a8a

Browse files
committed
[ConstraintSystem] Extend function type conversion mismatch coverage
Originally type mismatches associated with conversions between function types were only covered for coercions and assignments but fix coverage grew since then and now it makes sense to remove special case and let `repairFailures` take care of it.
1 parent 2d59365 commit 2d10a8a

File tree

3 files changed

+8
-20
lines changed

3 files changed

+8
-20
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4083,21 +4083,8 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
40834083

40844084
auto result = matchFunctionTypes(func1, func2, kind, flags, locator);
40854085

4086-
if (shouldAttemptFixes() && result.isFailure()) {
4087-
// If this is a contextual type mismatch failure
4088-
// let's give the solver a chance to "fix" it.
4089-
if (auto last = locator.last()) {
4090-
if (last->is<LocatorPathElt::ContextualType>())
4091-
break;
4092-
}
4093-
4094-
// If this is a type mismatch in assignment, we don't really care
4095-
// (yet) was it argument or result type mismatch, let's produce a
4096-
// diagnostic which mentions both function types.
4097-
auto *anchor = locator.getAnchor();
4098-
if (anchor && isa<AssignExpr>(anchor))
4099-
break;
4100-
}
4086+
if (shouldAttemptFixes() && result.isFailure())
4087+
break;
41014088

41024089
return result;
41034090
}

test/Constraints/enum_cases.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ let _ = arr.map(E.bar) // Ok
2222
let _ = arr.map(E.two) // expected-error {{cannot invoke 'map' with an argument list of type '(@escaping (Int, Int) -> E)'}}
2323
// expected-note@-1{{expected an argument list of type '((Self.Element) throws -> T)'}}
2424

25-
let _ = arr.map(E.tuple) // expected-error {{cannot invoke 'map' with an argument list of type '(@escaping ((x: Int, y: Int)) -> E)'}}
26-
// expected-note@-1{{expected an argument list of type '((Self.Element) throws -> T)'}}
25+
let _ = arr.map(E.tuple) // expected-error {{cannot convert value of type '((x: Int, y: Int)) -> E' to expected argument type '(String) throws -> T'}}
26+
// expected-error@-1 {{generic parameter 'T' could not be inferred}}
2727

2828
let _ = arr.map(G_E<String>.foo) // Ok
2929
let _ = arr.map(G_E<String>.bar) // Ok
3030
let _ = arr.map(G_E<String>.two) // expected-error {{cannot convert value of type '(String, String) -> G_E<String>' to expected argument type '(String) throws -> G_E<String>'}}
31-
let _ = arr.map(G_E<Int>.tuple) // expected-error {{cannot invoke 'map' with an argument list of type '(@escaping ((x: Int, y: Int)) -> G_E<Int>)'}}
32-
// expected-note@-1{{expected an argument list of type '((Self.Element) throws -> T)'}}
31+
let _ = arr.map(G_E<Int>.tuple) // expected-error {{cannot convert value of type '((x: Int, y: Int)) -> G_E<Int>' to expected argument type '(String) throws -> T'}}
32+
// expected-error@-1 {{generic parameter 'T' could not be inferred}}
3333

3434
let _ = E.foo("hello") // expected-error {{missing argument label 'bar:' in call}}
3535
let _ = E.bar("hello") // Ok

test/Constraints/tuple_arguments.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1702,7 +1702,8 @@ _ = x.map { (_: ()) in () }
17021702
// https://bugs.swift.org/browse/SR-9470
17031703
do {
17041704
func f(_: Int...) {}
1705-
let _ = [(1, 2, 3)].map(f) // expected-error {{cannot invoke 'map' with an argument list of type '(@escaping (Int...) -> ())'}}
1705+
let _ = [(1, 2, 3)].map(f) // expected-error {{cannot convert value of type '(Int...) -> ()' to expected argument type '((Int, Int, Int)) throws -> T'}}
1706+
// expected-error@-1 {{generic parameter 'T' could not be inferred}}
17061707
}
17071708

17081709
// rdar://problem/48443263 - cannot convert value of type '() -> Void' to expected argument type '(_) -> Void'

0 commit comments

Comments
 (0)