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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/topics/control-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

or [`sealed`](sealed-classes.md) type, or their nullable counterparts.
or [`sealed`](sealed-classes.md) type, and their nullable counterparts.
* branches of `when` don't cover all possible cases for this subject.

```kotlin
Expand Down