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

fix: when must have else branch if its subject is a enum/sealed/Boolean AND it's nullable #4089

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

PetrakovichVictoria
Copy link
Collaborator

@PetrakovichVictoria PetrakovichVictoria commented Mar 21, 2024

This is the important moment) Or maybe I don't know English:))

Ok:
Screenshot 2024-03-21 at 11 54 42

Nullable Bit and an absent else branch, not ok:
Screenshot 2024-03-21 at 11 54 59

@PetrakovichVictoria PetrakovichVictoria requested a review from a team as a code owner March 21, 2024 10:55
Copy link
Contributor

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale label Apr 21, 2024
@@ -92,7 +92,7 @@ val numericValue = when (getRandomBit()) {

In `when` _statements_, the `else` branch is mandatory in the following conditions:
* `when` has a subject of a `Boolean`, [`enum`](enum-classes.md),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Some more details for the example in the "Conversation" tab. For a non-nullable enum, an else branch is not needed (and the current wording with "or" sounds to me like it is needed). For a nullable enum, it's obligatory. This is why I think that and works better here.

Copy link
Contributor

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale label May 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants