-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
area:nullabilityitype:bugstat:needs triageEvery issue needs to have an "area" and "itype" labelEvery issue needs to have an "area" and "itype" label
Milestone
Description
Compiler version
Scala compiler version 3.3.2-RC1-bin-SNAPSHOT-git-ce1ce99 -- Copyright 2002-2023, LAMP/EPFL
Minimized code
def f(s: String|Null): String = {
if(s eq null) "foo" else s
}
def f2(s: String|Null): String = {
if(s ne null) s else "foo"
}
Compile with scalac -Yexplicit-nulls
.
Output
-- [E007] Type Mismatch Error: tests/explicit-nulls/pos/flow-predef-eq.scala:2:27 ---------------------------------------------------------
2 | if(s eq null) "foo" else s
| ^
| Found: (s : String | Null)
| Required: String
|
| longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: tests/explicit-nulls/pos/flow-predef-eq.scala:6:16 ---------------------------------------------------------
6 | if(s ne null) s else "foo"
| ^
| Found: (s : String | Null)
| Required: String
|
| longer explanation available when compiling with `-explain`
4 errors found
Expectation
Compiles.
The problem is that since s
is of type AnyRef | Null
, the eq
/ne
are actually extension methods in Predef
. The flow typing code looks for the pattern l.eq(r)
and l.==(r)
but not the more complicated (Predef.eq(l))(r)
.
Metadata
Metadata
Labels
area:nullabilityitype:bugstat:needs triageEvery issue needs to have an "area" and "itype" labelEvery issue needs to have an "area" and "itype" label