Skip to content

Commit a572c4b

Browse files
authored
Merge pull request #29549 from xedin/diag-all-function-type-mismatches
[ConstraintSystem] Extend function type conversion mismatch coverage
2 parents 9511295 + 6debe3d commit a572c4b

File tree

3 files changed

+19
-20
lines changed

3 files changed

+19
-20
lines changed

lib/Sema/CSSimplify.cpp

+13-15
Original file line numberDiff line numberDiff line change
@@ -2160,6 +2160,17 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
21602160

21612161
break;
21622162
}
2163+
2164+
// TODO(diagnostics): If there are any requirement failures associated
2165+
// with result types which are part of a function type conversion,
2166+
// let's record general conversion mismatch in order for it to capture
2167+
// and display complete function types.
2168+
//
2169+
// Once either reacher locators or better diagnostic presentation for
2170+
// nested type failures is available this check could be removed.
2171+
if (last->is<LocatorPathElt::FunctionResult>())
2172+
return getTypeMatchFailure(locator);
2173+
21632174
} else { // There are no elements in the path
21642175
auto *anchor = locator.getAnchor();
21652176
if (!(anchor &&
@@ -4083,21 +4094,8 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
40834094

40844095
auto result = matchFunctionTypes(func1, func2, kind, flags, locator);
40854096

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-
}
4097+
if (shouldAttemptFixes() && result.isFailure())
4098+
break;
41014099

41024100
return result;
41034101
}

test/Constraints/enum_cases.swift

+4-4
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

+2-1
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)