Skip to content

update: clarify null-handling behavior of==operator #4808

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

daniCsorbaJB
Copy link
Contributor

@daniCsorbaJB daniCsorbaJB commented Apr 16, 2025

This update is intended to clarify the null-handling behavior of the == operator for KT-74113

Restructured text approved by Nikita Bobko

@daniCsorbaJB daniCsorbaJB requested a review from a team as a code owner April 16, 2025 09:49
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 17, 2025
@koshachy koshachy removed the Stale label May 22, 2025
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.

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 Jul 24, 2025
@daniCsorbaJB daniCsorbaJB marked this pull request as draft July 29, 2025 11:11
@daniCsorbaJB daniCsorbaJB removed the Stale label Aug 7, 2025
@daniCsorbaJB daniCsorbaJB marked this pull request as ready for review August 7, 2025 12:28
@daniCsorbaJB daniCsorbaJB force-pushed the clarify-equal-operator branch from f3e5341 to 8beefa7 Compare August 7, 2025 12:31
@sarahhaggarty sarahhaggarty self-assigned this Aug 7, 2025
Copy link
Collaborator

@sarahhaggarty sarahhaggarty left a comment

Choose a reason for hiding this comment

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

I have some suggestions for the text :)

Comment on lines 186 to 187
Kotlin calls `.equals()` when neither operand is the `null` literal and the comparison isn’t between two floating-point types.
Otherwise, `===` is used for `null` literal checks, and non-null floating-point values are compared by numeric value.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of "the null literal" can we say "a null value"?
And "=== is used to check for null values" rather than "=== is used for null literal checks"?

And can you make the second sentence active? "Kotlin uses ===" or something like that?

Copy link
Contributor Author

@daniCsorbaJB daniCsorbaJB Aug 11, 2025

Choose a reason for hiding this comment

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

Instead of "the null literal" can we say "a null value"?

🤔 It's an important difference here. With two expressions A and B, A == B expands to A?.equals(B) ?: (B === null) even with a null value. If either operand is literal null, A == B instead expands to A === B.

And can you make the second sentence active? "Kotlin uses ===" or something like that?

Sure thing 👍

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.

3 participants