[SR-10280] Unexpected error when initializing a variable or constant of function type with a method with argument labels. #52680
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler in itself
type checker
Area → compiler: Semantic analysis
Environment
Apple Swift version 5.0 (swiftlang-1001.0.69.5 clang-1001.0.46.3)
Target: x86_64-apple-darwin18.5.0
Additional Detail from JIRA
md5: 3890af4f471603c40e2c1d9b6768d69b
Issue Description:
Given the following code:
struct S {
func f(a: Int) -> Int { return 1 }
func f(b: String) -> Int { return 2 }
{{}}}
let s = S()
let ff1 = S.f(s) as (Int) -> Int
let ff2 = S.f(s) as (String) -> Int
The compiler emits the following suspicious errors:
error: 'f' produces 'Int', not the expected contextual result type 'Int'
let ff1 = S.f(s) as (Int) -> Int
{{ ^}}
error: 'f' produces 'Int', not the expected contextual result type 'Int'
let ff2 = S.f(s) as (String) -> Int
{{ ^}}
If the argument labels are omitted (i.e. func f(_ a: Int) -> Int { return 1 }) the errors disappear.
The same error can be observed if S is a class or an enum but not if f are global functions.
The text was updated successfully, but these errors were encountered: