Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-10280] Unexpected error when initializing a variable or constant of function type with a method with argument labels. #52680

Open
swift-ci opened this issue Apr 3, 2019 · 1 comment
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

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Apr 3, 2019

Previous ID SR-10280
Radar None
Original Reporter esconner (JIRA User)
Type Bug
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
Votes 0
Component/s Compiler
Labels Bug, TypeChecker
Assignee None
Priority Medium

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.

@belkadan
Copy link
Contributor

belkadan commented Apr 3, 2019

Odd-looking workaround:

let ff1 = S.f(a:)(s) as (Int) -> Int
let ff2 = S.f(b:)(s) as (String) -> Int

But yeah, I'd say this is still a bug.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

2 participants