-
Notifications
You must be signed in to change notification settings - Fork 1.1k
An alternative feature to UnsafeNulls: UnsafeJavaReturn #15096
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
Closed
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d4ae150
Add unsafeJavaReturn
noti0na1 c4836fb
Fix class vals, keep annotation loonger
noti0na1 0e797c0
Add comment
noti0na1 8a41011
Add a special rule for CanEqualNull
noti0na1 31b6dd2
Add comments
noti0na1 a4ec903
Rename test folder
noti0na1 ee01fe4
Fix unary function call
noti0na1 a9fd424
Fix bugs in the PR
noti0na1 1b3fb99
Fix comment
noti0na1 2a885b8
Mark UnsafeJavaReturn as experimental
noti0na1 a874a9c
Add unsafeJavaReturn to MiMaFilters
noti0na1 ad4bdc3
Add CanEqualNull to experimentalDefinitionInLibrary
noti0na1 70bf99d
Delete extra definition
noti0na1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package scala.annotation | ||
|
||
/** An annotation makes reference types comparable to `null` in explicit nulls. | ||
* `CanEqualNull` is a special refining annotation. An annotated type is equivalent to the original type. | ||
* | ||
* For example: | ||
* ```scala | ||
* val s1: String = ??? | ||
* s1 == null // error | ||
* val s2: String @CanEqualNull = ??? | ||
* s2 == null // ok | ||
* | ||
* // String =:= String @CanEqualNull | ||
* val s3: String = s2 | ||
* val s4: String @CanEqualNull = s1 | ||
* | ||
* val ss: Array[String @CanEqualNull] = ??? | ||
* ss.map(_ == null) | ||
* ``` | ||
*/ | ||
@experimental | ||
final class CanEqualNull extends RefiningAnnotation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import language.experimental.unsafeJavaReturn | ||
|
||
import java.math.MathContext, MathContext._ | ||
|
||
val x: MathContext = DECIMAL32 | ||
val y: MathContext = MathContext.DECIMAL32 | ||
|
||
import java.io.File | ||
|
||
val s: String = File.separator | ||
import java.time.ZoneId | ||
|
||
val zids: java.util.Set[String] = ZoneId.getAvailableZoneIds | ||
val zarr: Array[String] = ZoneId.getAvailableZoneIds.toArray(Array.empty[String | Null]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import scala.language.experimental.unsafeJavaReturn | ||
|
||
import java.lang.reflect.Method | ||
|
||
def getMethods(f: String): List[Method] = | ||
val clazz = Class.forName(f) | ||
val methods = clazz.getMethods | ||
if methods == null then List() | ||
else methods.toList | ||
|
||
def getClass(o: AnyRef): Class[?] = o.getClass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class J1 { | ||
J2 getJ2() { return new J2(); } | ||
} | ||
|
||
class J2 { | ||
J1 getJ1() { return new J1(); } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import scala.language.experimental.unsafeJavaReturn | ||
|
||
def f = { | ||
val j: J2 = new J2() | ||
j.getJ1().getJ2().getJ1().getJ2().getJ1().getJ2() | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.