Skip to content

Commit 4339017

Browse files
[tests] Adding test for diagnostics for function type coerce failure
1 parent 0300139 commit 4339017

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

test/expr/cast/as_coerce.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,28 @@ let _: Int = any as Int // expected-error {{'Any' is not convertible to 'Int'}}
163163
// expected-note@-1 {{did you mean to use 'as!' to force downcast?}} {{18-20=as!}}
164164
let _: Int? = any as Int // expected-error {{'Any' is not convertible to 'Int'}}
165165
// expected-note@-1 {{did you mean to use 'as?' to conditionally downcast?}} {{19-21=as?}}
166+
167+
// https://github.com/apple/swift/issues/63926
168+
169+
do {
170+
func fn(_: Int) {} // expected-note {{found candidate with type '(Int) -> ()'}}
171+
// expected-note@-1 {{candidate '(Int) -> ()' has 1 parameter, but context '() -> Void' has 0}}
172+
func fn(_: Bool) {} // expected-note {{found candidate with type '(Bool) -> ()'}}
173+
// expected-note@-1 {{candidate '(Bool) -> ()' has 1 parameter, but context '() -> Void' has 0}}
174+
175+
func fn_1(_: Bool) {}
176+
177+
let i = 0
178+
// Missing parameters.
179+
(fn as (Int, Int) -> Void)(i, i) // expected-error {{cannot convert value of type '(Int) -> ()' to type '(Int, Int) -> Void' in coercion}}
180+
(fn as (Bool, Bool) -> Void)(i, i) // expected-error {{cannot convert value of type '(Bool) -> ()' to type '(Bool, Bool) -> Void' in coercion}}
181+
// expected-error@-1 2{{type 'Int' cannot be used as a boolean; test for '!= 0' instead}}
182+
(fn as (Int, Bool) -> Void)(i, i) // expected-error {{cannot convert value of type '(Int) -> ()' to type '(Int, Bool) -> Void' in coercion}}
183+
// expected-error@-1 {{type 'Int' cannot be used as a boolean; test for '!= 0' instead}}
184+
(fn as (String) -> Void)(i) // expected-error {{no exact matches in reference to local function 'fn'}}
185+
// expected-error@-1 {{cannot convert value of type 'Int' to expected argument type 'String'}}
186+
187+
// Extraneous parameters.
188+
(fn as () -> Void)() // expected-error {{no exact matches in reference to local function 'fn'}}
189+
(fn_1 as () -> Void)() // expected-error {{cannot convert value of type '(Bool) -> ()' to type '() -> Void' in coercion}}
190+
}

0 commit comments

Comments
 (0)