Skip to content

Commit 1cc1e58

Browse files
committed
[Sema] Don't look through CoerceExprs in markDirectCallee
Doing so prevented the coercion of a function with argument labels to a user-written function type, as the latter cannot contain argument labels. This commit changes the behaviour such that the referenced function is considered to be unapplied, meaning it has its argument labels stripped, therefore allowing the coercion. Resolves SR-11429.
1 parent dff4c78 commit 1cc1e58

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -897,12 +897,6 @@ namespace {
897897
continue;
898898
}
899899

900-
// Coercions can be used for disambiguation.
901-
if (auto coerce = dyn_cast<CoerceExpr>(callee)) {
902-
callee = coerce->getSubExpr();
903-
continue;
904-
}
905-
906900
// We're done.
907901
break;
908902
}

test/Sema/suppress-argument-labels-in-types.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,21 @@ class C0 {
204204

205205
// Check diagnostics changes.
206206
let _ = min(Int(3), Float(2.5)) // expected-error{{cannot convert value of type 'Float' to expected argument type 'Int'}}
207+
208+
// SR-11429
209+
func testIntermediateCoercions() {
210+
_ = (f1 as (Int, Int) -> Int)(a: 0, b: 1) // expected-error {{extraneous argument labels 'a:b:' in call}}
211+
_ = (f1 as (Int, Int) -> Int)(0, 1)
212+
213+
typealias Magic<T> = T
214+
_ = (f1 as Magic)(a: 0, b: 1) // expected-error {{extraneous argument labels 'a:b:' in call}}
215+
_ = (f1 as Magic)(0, 1)
216+
217+
_ = (f4 as (Int, Int) -> Int)(0, 0)
218+
_ = (f4 as (Double, Double) -> Double)(0, 0)
219+
220+
func iuoReturning() -> Int! {}
221+
_ = (iuoReturning as () -> Int?)()
222+
_ = (iuoReturning as Magic)()
223+
_ = (iuoReturning as () -> Int)() // expected-error {{'() -> Int?' is not convertible to '() -> Int'; did you mean to use 'as!' to force downcast?}}
224+
}

0 commit comments

Comments
 (0)