-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add special case to init checker to always allow certain methods
Closes #14275 - Treats mehtods `ne`, `eq`, `isInstanceOf`, and `asInstanceOf` as safe to call, regardless of initialization Signed the CLA - @Xavientois Review by @liufengyun
- Loading branch information
1 parent
1130c52
commit ec794f3
Showing
4 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 @@ | ||
final class MyAsInstanceOfClass(o: MyAsInstanceOfClass) { | ||
val other: MyAsInstanceOfClass = { | ||
if (o.asInstanceOf[MyAsInstanceOfClass].oRef ne null) o // error | ||
else new MyAsInstanceOfClass(this) | ||
} | ||
val oRef = o | ||
} |
This file contains 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,13 @@ | ||
final class MyNeClass(o: MyNeClass) { | ||
val other: MyNeClass = { | ||
if (o ne null) o // o is cold, but ne is always valid | ||
else new MyNeClass(this) | ||
} | ||
} | ||
|
||
final class MyEqClass(o: MyEqClass) { | ||
val other: MyEqClass = { | ||
if (o eq null) new MyEqClass(this) // o is cold, but eq is always valid | ||
else o | ||
} | ||
} |
This file contains 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 @@ | ||
final class MyIsInstanceOfClass(o: MyIsInstanceOfClass) { | ||
val other: MyIsInstanceOfClass = { | ||
if (!o.isInstanceOf[Object]) new MyIsInstanceOfClass(this) // o is cold, but isInstanceOf is always valid | ||
else o | ||
} | ||
} | ||
|
||
final class MyAsInstanceOfClass(o: MyAsInstanceOfClass) { | ||
val other: MyAsInstanceOfClass = { | ||
if (o.asInstanceOf[Object] ne null) o // o is cold, but ne and AsInstanceOf is always valid | ||
else new MyAsInstanceOfClass(this) | ||
} | ||
} | ||
|
||
final class MyAsInstanceOfFieldClass(o: MyAsInstanceOfFieldClass) { | ||
val oRef = o | ||
val other: MyAsInstanceOfFieldClass = { | ||
if (this.asInstanceOf[MyAsInstanceOfFieldClass].oRef ne null) oRef // o is cold, but ne and AsInstanceOf is always valid | ||
else new MyAsInstanceOfFieldClass(this) | ||
} | ||
} | ||
|