-
Notifications
You must be signed in to change notification settings - Fork 10.5k
TypeCheckType: Make ExistentialAny
warn rather than error until Swift 7
#78347
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
Conversation
@swift-ci please smoke test macOS |
ec8d16c
to
18e9176
Compare
@swift-ci please smoke test macOS |
3d17660
to
4531c1d
Compare
#78398 makes the escalation actually work. |
… Swift 7 The conditions for when and how (error or warning) a missing `any` is diagnosed are a mouthful even if we set aside source compatibility hacks. This change builds on swiftlang#78347 by downgrading all missing `any` diagnostics to warnings until Swift 7, making the behavior less confusing for developers and giving us an opportunity to patch up remaining holes in the diagnosis gracefully.
ExistentialAny
warn rather than error until Swift 7any
until Swift 7
any
until Swift 7ExistentialAny
warn rather than error until Swift 7
@swift-ci please smoke test macOS |
4531c1d
to
a27110f
Compare
… Swift 7 The conditions for when and how (error or warning) a missing `any` is diagnosed are a mouthful even if we set aside source compatibility hacks. This change builds on swiftlang#78347 by downgrading all missing `any` diagnostics to warnings until Swift 7, making the behavior less confusing for developers and giving us an opportunity to patch up remaining holes in the diagnosis gracefully.
a27110f
to
efce791
Compare
@slavapestov ping |
…rror This enables programmers to opt in to assisted adoption of the new syntax without breaking code and, thus, migrate in increments.
Allows users to unconditionally escalate `ExistentialAny` warnings to errors with `-Werror <group>`.
efce791
to
59c15c7
Compare
I'm not super opposed to this but I'm also not sure if the change is of much value. I've been using the existential-any flag pretty much in every project since Swift 5.8 (or was it 5.7), and I've never encountered a situation where fixing the code isn't trivial. IIRC in almost all cases the compiler also properly tells you what to do to fix, a lot of times you can just accept the proposed FIXIT. If one doesn't want to guard their code against not using existential-any, then they could have just not enabled the flag. If they have enabled the flag, then fixing things is trivial so I'm not sure what a downgrade to warning achieves in practice. The only value I can see for this change is for the cases where existential-any is being buggy and is throwing an incorrect error. /__w/enumerator-macro/enumerator-macro/Sources/EnumeratorMacroImpl/Types/WithNormalizedTypeName.swift:8:28: error: use of protocol 'WithNormalizedTypeName' as a type must be written 'any WithNormalizedTypeName'
6 | func bestEffortTypeName<T>(_ type: T.Type = T.self) -> String {
7 | switch type {
8 | case let customType as WithNormalizedTypeName.Type:
| `- error: use of protocol 'WithNormalizedTypeName' as a type must be written 'any WithNormalizedTypeName'
9 | customType.normalizedTypeName
10 | default: (The error is unfixable btw, no variation of using/not-using |
@MahdiBM I am going to post a more detailed motivation on the forums soon. Let’s defer the discussion until then. I will leave a link here.
What’s the compiler where this is unfixable? |
I tried to compile that project again and it does appear that the recent 6.1 / main toolchains don't have that problem anymore so I guess we're good now. But what I described did use to be the case. |
Superseded by #78459. |
This enables programmers to opt in to assisted adoption of the new syntax without breaking code and, thus, migrate in increments, whilst retaining the option to unconditionally escalate warnings with
-Werror
.