Closed
Description
Compiler version
3.1.0 (using -Ysafe-init
)
Minimized code
final class MyClass(o: MyClass) {
val other: MyClass = {
if (o ne null) o
else new MyClass(this)
}
}
Output
[warn] -- Warning: .../TesT.scala:5:8
[warn] 5 | if (o ne null) o
[warn] | ^^^^^^^^^
[warn] |Call method MyClass.this.o.ne(null) on a value with an unknown initialization. Calling trace:
[warn] | -> else new MyClass(this) [ TesT.scala:6 ]
[warn] | -> final class MyClass(o: MyClass) { [ TesT.scala:3 ]
[warn] one warning found
Using eq
instead of ne
results in a similar warning.
Expectation
Unless I'm missing something, calling ne
or eq
is safe on any value (in fact, they can even be called on null
). So I would expect no warning in these cases.