Skip to content

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

Closed
wants to merge 3 commits into from

Conversation

AnthonyLatsis
Copy link
Collaborator

@AnthonyLatsis AnthonyLatsis commented Dec 23, 2024

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.

@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please smoke test macOS

@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please smoke test macOS

@AnthonyLatsis
Copy link
Collaborator Author

#78398 makes the escalation actually work.

AnthonyLatsis added a commit to AnthonyLatsis/swift that referenced this pull request Jan 7, 2025
… 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.
@AnthonyLatsis AnthonyLatsis changed the title TypeCheckType: Make ExistentialAny warn rather than error until Swift 7 TypeCheckType: Warn, not error, about missing existential any until Swift 7 Jan 7, 2025
@AnthonyLatsis AnthonyLatsis changed the title TypeCheckType: Warn, not error, about missing existential any until Swift 7 TypeCheckType: Make ExistentialAny warn rather than error until Swift 7 Jan 7, 2025
@AnthonyLatsis AnthonyLatsis changed the title TypeCheckType: Make ExistentialAny warn rather than error until Swift 7 TypeCheckType: Make ExistentialAny warn rather than error until Swift 7 Jan 7, 2025
@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please smoke test macOS

AnthonyLatsis added a commit to AnthonyLatsis/swift that referenced this pull request Jan 7, 2025
… 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.
@AnthonyLatsis
Copy link
Collaborator Author

@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>`.
@MahdiBM
Copy link

MahdiBM commented Jan 22, 2025

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.
I think enumerator-macro is actually encountering such an issue right now on nightlies. But then that's a bug to fix, not to ignore, and it doesn't sound like this was the reason for the proposed change either.

/__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 any satisfies the compiler)

@AnthonyLatsis
Copy link
Collaborator Author

@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.

(The error is unfixable btw, no variation of using/not-using any satisfies the compiler)

What’s the compiler where this is unfixable? any WithNormalizedTypeName.Type works on main.

@MahdiBM
Copy link

MahdiBM commented Jan 23, 2025

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.

@AnthonyLatsis
Copy link
Collaborator Author

https://forums.swift.org/t/downgrade-existential-any-errors-to-warnings-until-a-future-language-mode/77477

@AnthonyLatsis
Copy link
Collaborator Author

Superseded by #78459.

@AnthonyLatsis AnthonyLatsis deleted the tuber-magnatum branch February 12, 2025 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants