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-12862] Misleading error when trying to implement Optional requirement with IUO #55308

Open
swift-ci opened this issue May 22, 2020 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-12862
Radar None
Original Reporter cukier (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, TypeChecker
Assignee None
Priority Medium

md5: a5e4f9ce134e3079fdd7dc9350acca61

Issue Description:

protocol Proto {
    var test: Int? { get set }
}
struct Struct: Proto {
    var test: Int! = 123
}

This code will give you an error like this:

main.swift:6:8: error: type 'Struct' does not conform to protocol 'Proto'
struct Struct: Proto {
       ^
main.swift:7:9: note: candidate has non-matching type 'Int?'
    var test: Int! = 123
        ^
main.swift:4:9: note: protocol requires property 'test' with type 'Int?'; do you want to add a stub?
    var test: Int? { get set }
        ^

I'm talking specifically about the "non-matching type 'Int?'" note. It's silly to say that `Int?` doesn't match itself. Swift should decide if `Int?` and `Int!` are the same type, or different types.

If they are the same type, the code should compile.
If they are not the same type, then the error message should say the correct type (i.e. `Int!`)

The problem happens also with unannotated obj-c classes, which makes the problem harder to notice, because it's not immediately obvious that `@property NSNumber *foo;` isn't an optional when compiler tells you it is.

@theblixguy
Copy link
Collaborator

They're the same type, but this doesn't compile because IUO is a flag now (vs. a distinct type as it was before) and because it's missing on the witness, the match fails. We could certainly improve the diagnostics here.

@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 diagnostics QoI Bug: Diagnostics Quality of Implementation type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants