Skip to content

Conversation

@sarahhaggarty
Copy link
Collaborator

@sarahhaggarty sarahhaggarty commented Nov 10, 2025

This PR improves the quality of examples on the Type checks and casts page, and answers questions received in external feedback.

@sarahhaggarty sarahhaggarty requested a review from a team as a code owner November 10, 2025 15:02
@sarahhaggarty sarahhaggarty requested a review from serras November 10, 2025 15:03
Comment on lines +54 to +58
if (animal is Dog) {
println("Special care instructions: This is a dog.")
} else if (animal is Cat) {
println("Special care instructions: This is a cat.")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that showing the same version with when could be interesting at this point.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see that there's an example below

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes! I wanted to explain how when worked with smart casts later :)

>
{style="tip"}

## is and !is operators
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a thought, to link it to the page title and intro, this header could be "Check operators", "Type checks", or "Checks with is and !is operators"

>
{type="tip"}

## Type casts
Copy link
Contributor

Choose a reason for hiding this comment

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

I get the intention, but with this additional subheader, we're losing subsection labels in the right-hand menu that seem important

```
{kotlin-runnable="true" kotlin-min-compiler-version="2.0" id="kotlin-safe-cast-operator"}

#### Nullable types
Copy link
Contributor

Choose a reason for hiding this comment

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

I think for consistency, as and as? operators should either have each a corresponding subsection, or none at all. Nullable types is rather short and could be just a part of Casting operators. But, again, if we want them to be visible in the right menu, two subheaders would be better.

### Smart cast prerequisites
#### Smart cast prerequisites

> Note that smart casts work only when the compiler can guarantee that the variable won't change between the check and its usage.
Copy link
Contributor

Choose a reason for hiding this comment

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

I know it's not a part of your changes, just caught my eye that a note starts with "Note that" and has a warning color. Also, the table is simple enough to be a MD table


#### Control flow

Smart casts work not only for `if` conditional expressions but also for [`when` expressions](control-flow.md#when-expressions-and-statements):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Smart casts work not only for `if` conditional expressions but also for [`when` expressions](control-flow.md#when-expressions-and-statements):
Smart casts work not only for `if` conditional expressions, but also for [`when` expressions](control-flow.md#when-expressions-and-statements):


var status: Status = robo.status()
while (status is Ok) {
// The compiler smart casts status to OK type so the currentRoom
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// The compiler smart casts status to OK type so the currentRoom
// The compiler smart casts status to OK type, so the currentRoom

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.

4 participants