Skip to content

[Sema] Improving integer literal as boolean diagnostic #63799

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

Merged
merged 1 commit into from
Feb 21, 2023

Conversation

LucianoPAlmeida
Copy link
Contributor

Improving integer literal diagnostics to avoid test for '!= 0' instead as they don't make sense in a literal context.
Also additionally covering cases where we currently produce a Optional type 'Int?' cannot be used as a boolean; test for '!= nil' instead on contextual mismatch in situations like if 0? {} in the same way.

There is an extra case to cover on this

let variable = 0
if variable? {} // type of expression is ambiguous without more context

but that is a separate situation and is covered in another issue.

Resolves #63753

@LucianoPAlmeida
Copy link
Contributor Author

@swift-ci Please smoke test

Copy link
Contributor

@hamishknight hamishknight left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@LucianoPAlmeida
Copy link
Contributor Author

@swift-ci Please test

@LucianoPAlmeida LucianoPAlmeida merged commit c82282a into swiftlang:main Feb 21, 2023
@LucianoPAlmeida LucianoPAlmeida deleted the int-literal-diags branch February 25, 2023 19:07
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.

Int-as-Bool diagnostic suggesting != 0 should ignore literals
3 participants