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

Consider nullable annotations in explicit nulls #21629

Open
noti0na1 opened this issue Sep 23, 2024 · 8 comments · May be fixed by #21953
Open

Consider nullable annotations in explicit nulls #21629

noti0na1 opened this issue Sep 23, 2024 · 8 comments · May be fixed by #21953
Assignees
Labels

Comments

@noti0na1
Copy link
Member

The @NotNull and @NonNullable type annotations are currently used by explicit nulls to not nullify (or add flexible type to) a reference type from Java signatures.

In addition to these annotations, I suggest we also consider the @Nullable annotation. It indicates a value can indeed be null. In this case, we will always nullify the type (adding | Null), instead of adding a flexible type.

// in Java
@Nullable String f(String s)

// in Scala with explicit nulls currently
def f(s: (String)?): (String)?

// in Scala with explicit nulls considering the annotation
def f(s: (String)?): String | Null

A list of @Nullable annotations we may want to consider:

javax.annotation.Nullable
org.jetbrains.annotations.Nullable
org.jspecify.annotations.Nullable
...
@olhotak
Copy link
Contributor

olhotak commented Sep 23, 2024

There is already some support for this (or was it disabled at some point?). See NotNullAnnots in Definitions.scala and uses of that. def hasNotNullAnnot in JavaNullInterop.

Oh, sorry, I misunderstood.

@noti0na1
Copy link
Member Author

Not sure about the current status of Java ecosystem. I guess jspecify is the latest standard for this kind of annotations?

@olhotak
Copy link
Contributor

olhotak commented Sep 23, 2024

Perhaps this could be a good introductory task for @HarrisL2

@noti0na1 noti0na1 added the good first issue Perfect for someone who wants to get started contributing label Sep 23, 2024
@noti0na1
Copy link
Member Author

noti0na1 commented Sep 23, 2024

This is a list of annotations considered by Kotlin:
https://github.com/JetBrains/kotlin/blob/a9ff22693479cabd201909a06e6764c00eddbf7b/core/compiler.common.jvm/src/org/jetbrains/kotlin/load/java/JvmAnnotationNames.kt

We should update our existing list as well.

@rajRishi22
Copy link

Hi @noti0na1 , I want to work on this issue can you please assign me this one ?

@noti0na1
Copy link
Member Author

Hi @rajRishi22 , feel free to work on this issue.

HarrisL2 added a commit to HarrisL2/scala3 that referenced this issue Nov 14, 2024
@HarrisL2 HarrisL2 linked a pull request Nov 14, 2024 that will close this issue
@noti0na1
Copy link
Member Author

Reassign to @HarrisL2, since he is already working on this.

@HarrisL2
Copy link
Contributor

Reassign to @HarrisL2, since he is already working on this.

Got it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants