File tree Expand file tree Collapse file tree 3 files changed +43
-0
lines changed
compiler/src/dotty/tools/dotc/typer
tests/explicit-nulls/unsafe-common/unsafe-java-call Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -3746,6 +3746,15 @@ class Typer extends Namer
3746
3746
if target <:< pt then
3747
3747
return readapt(tree.cast(target))
3748
3748
3749
+ // if unsafeNulls is enabled, try to strip nulls from Java function calls
3750
+ if Nullables .unsafeNullsEnabled then
3751
+ tree match
3752
+ case _ : Apply if tree.symbol.is(JavaDefined ) =>
3753
+ wtp match
3754
+ case OrNull (wtp1) => return readapt(tree.cast(wtp1))
3755
+ case _ =>
3756
+ case _ =>
3757
+
3749
3758
def recover (failure : SearchFailureType ) =
3750
3759
if canDefineFurther(wtp) || canDefineFurther(pt) then readapt(tree)
3751
3760
else err.typeMismatch(tree, pt, failure)
Original file line number Diff line number Diff line change
1
+ public class J {
2
+ public String f1 () {
3
+ return "" ;
4
+ }
5
+
6
+ public int f2 () {
7
+ return 0 ;
8
+ }
9
+
10
+ public <T > T g1 () {
11
+ return null ;
12
+ }
13
+ }
Original file line number Diff line number Diff line change
1
+ import scala .language .unsafeNulls
2
+
3
+ val j : J = new J
4
+
5
+ val s1 : String = j.f1()
6
+
7
+ val i1 : Int = j.f2()
8
+
9
+ val s2 : String = j.g1[String ]()
10
+
11
+ val i2 : Int = j.g1[Int ]()
12
+
13
+ val a1 : Any = j.g1[Any ]()
14
+
15
+ val ar1 : AnyRef = j.g1[AnyRef ]()
16
+
17
+ val n1 : Null = j.g1[Null ]()
18
+
19
+ val ar2 : AnyRef = j.g1[Null ]()
20
+
21
+ def clo [T ]: T = j.g1[T ]()
You can’t perform that action at this time.
0 commit comments