Skip to content

Add stableNull annotation to force tracking mutable fields #23528

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 4 commits into
base: main
Choose a base branch
from

Conversation

noti0na1
Copy link
Member

@noti0na1 noti0na1 commented Jul 15, 2025

class A:
  @stableNull var s: String | Null = null
  def getS: String =
    if s == null then s = ""
    s

The annotation will be added as private in scala for now. We plan to make it public in the next major release.

@olhotak
Copy link
Contributor

olhotak commented Jul 15, 2025

I think stableNull would be a better name.

@noti0na1 noti0na1 marked this pull request as ready for review July 16, 2025 11:42
@noti0na1 noti0na1 requested a review from a team as a code owner July 16, 2025 11:42
@noti0na1 noti0na1 requested a review from hamzaremmal July 16, 2025 11:43
@noti0na1 noti0na1 changed the title Add nullTrackable annotation to force tracking mutable fields Add stableNull annotation to force tracking mutable fields Jul 16, 2025
@SethTisue
Copy link
Member

If I understand correctly, then before becoming public, this would be considered by the SIP committee as part of the explicit-nulls feature.

package scala.annotation

/** An annotation that can be used to mark a mutable field as trackable for nullability.
* With explicit nulls, a normal mutable field can be tracked for nullability by flow typing,
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
* With explicit nulls, a normal mutable field can be tracked for nullability by flow typing,
* With explicit nulls, a normal mutable field cannot be tracked for nullability by flow typing,

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