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

Bad diagnostic for any P! #72662

Open
AnthonyLatsis opened this issue Mar 28, 2024 · 6 comments · May be fixed by #74461
Open

Bad diagnostic for any P! #72662

AnthonyLatsis opened this issue Mar 28, 2024 · 6 comments · May be fixed by #74461
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself diagnostics QoI Bug: Diagnostics Quality of Implementation existentials Feature: values of types like `any Collection`, `Any` and `AnyObject`; type-erased values good first issue Good for newcomers implicitly unwrapped optionals Feature → types: Implicitly unwrapped optional types, aka IUO swift 6.0 type checker Area → compiler: Semantic analysis TypeResolver types Feature: types unexpected behavior Bug: Unexpected behavior or incorrect output

Comments

@AnthonyLatsis
Copy link
Collaborator

AnthonyLatsis commented Mar 28, 2024

Description

No response

Reproduction

protocol P {}

// error: using '!' is not allowed here; perhaps '?' was intended? [implicitly_unwrapped_optional_in_illegal_position]
// error: optional 'any' type must be written '(any P2)?' [incorrect_optional_any]
let _: any P!

Expected behavior

A single error, optional 'any' type must be written '(any P)!', as in the case of let _: any P?.

Environment

Swift version 6.0-dev (LLVM 48dc0c6fa01ce9e, Swift 19fbe5b)
Target: x86_64-apple-macosx14.0

Additional information

This https://github.com/apple/swift/labels/good%20first%20issue will suit an experienced Swift user.

@AnthonyLatsis AnthonyLatsis added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself good first issue Good for newcomers diagnostics QoI Bug: Diagnostics Quality of Implementation type checker Area → compiler: Semantic analysis TypeResolver existentials Feature: values of types like `any Collection`, `Any` and `AnyObject`; type-erased values unexpected behavior Bug: Unexpected behavior or incorrect output types Feature: types swift 6.0 implicitly unwrapped optionals Feature → types: Implicitly unwrapped optional types, aka IUO labels Mar 28, 2024
@CrazyFanFan
Copy link
Contributor

@AnthonyLatsis Would modifying PrintOptions::forDiagnosticArguments() be the correct solution to this problem? If so, I believe I could attempt to resolve it.

@AnthonyLatsis
Copy link
Collaborator Author

No, this is a problem with the diagnosis of invalid code, not the format used to print diagnostic messages.

@fabricerenard12
Copy link

fabricerenard12 commented Apr 3, 2024

Hi AnthonyLatsis, if no one is already addressing this issue, I would love to start working on it. Could you please assign it to me?

@iMostfa
Copy link
Contributor

iMostfa commented Jun 16, 2024

Hi @AnthonyLatsis i'm interest in this issue,

i've made a PoC solution for this issue here, i'm not sure if it's the right way to fix it though, 71d3c4f

i wanted to avoid touching TypeResolver::resolveImplicitlyUnwrappedOptionalType
and instead try to fix it from TypeResolver::resolveExistentialType

but i found that it's not possible as already too late we get a diagnostics emitted from: TypeResolver::resolveImplicitlyUnwrappedOptionalType before we emit the another (correct diagnostics in this case) from resolveExistentialType:

i ran tests in sema and it looks like my fix doesn't cause any regressions, what do you think ?

this's the current state after applying my fix:

Screenshot 2024-06-16 at 18 11 46

and tests in sema are ✅

would apperciate if i get this one assigned to me, and a hint if my approach needs to be changed

@AnthonyLatsis
Copy link
Collaborator Author

Hi, Mostfa! We prefer doing code review through pull requests, so you are very much encouraged to open one to apple:main if you are ready to discuss a solution.

@iMostfa iMostfa linked a pull request Jun 16, 2024 that will close this issue
@iMostfa
Copy link
Contributor

iMostfa commented Jun 16, 2024

Thanks @AnthonyLatsis For the quick response

PR Opened #74461

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 itself diagnostics QoI Bug: Diagnostics Quality of Implementation existentials Feature: values of types like `any Collection`, `Any` and `AnyObject`; type-erased values good first issue Good for newcomers implicitly unwrapped optionals Feature → types: Implicitly unwrapped optional types, aka IUO swift 6.0 type checker Area → compiler: Semantic analysis TypeResolver types Feature: types unexpected behavior Bug: Unexpected behavior or incorrect output
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants