File tree 2 files changed +18
-0
lines changed
compiler/src/dotty/tools/dotc/typer 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -115,6 +115,10 @@ object Nullables:
115
115
testSym(tree.symbol, l)
116
116
case Apply (Select (Literal (Constant (null )), _), r :: Nil ) =>
117
117
testSym(tree.symbol, r)
118
+ case Apply (Apply (op, l :: Nil ), Literal (Constant (null )) :: Nil ) =>
119
+ testPredefSym(op.symbol, l)
120
+ case Apply (Apply (op, Literal (Constant (null )) :: Nil ), r :: Nil ) =>
121
+ testPredefSym(op.symbol, r)
118
122
case _ =>
119
123
None
120
124
@@ -123,6 +127,13 @@ object Nullables:
123
127
else if sym == defn.Any_!= || sym == defn.Object_ne then Some ((operand, false ))
124
128
else None
125
129
130
+ private def testPredefSym (opSym : Symbol , operand : Tree )(using Context ) =
131
+ if opSym.owner == defn.ScalaPredefModuleClass then
132
+ if opSym.name == nme.eq then Some ((operand, true ))
133
+ else if opSym.name == nme.ne then Some ((operand, false ))
134
+ else None
135
+ else None
136
+
126
137
end CompareNull
127
138
128
139
/** An extractor for null-trackable references */
Original file line number Diff line number Diff line change
1
+ def f (s : String | Null ): String = {
2
+ if (s eq null ) " foo" else s
3
+ }
4
+
5
+ def f2 (s : String | Null ): String = {
6
+ if (s ne null ) s else " foo"
7
+ }
You can’t perform that action at this time.
0 commit comments