You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Scala compiler version 3.3.2-RC1-bin-SNAPSHOT-git-ce1ce99 -- Copyright 2002-2023, LAMP/EPFL
Minimized code
deff(s: String|Null):String= {
if(s eq null) "foo"else s
}
deff2(s: String|Null):String= {
if(s ne null) s else"foo"
}
Compile with scalac -Yexplicit-nulls.
Output
-- [E007] TypeMismatchError: 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] TypeMismatchError: 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).
The text was updated successfully, but these errors were encountered:
I tried adding a search for this pattern to the CompareNull extractor, but got stuck. To determine whether the operation is eq or ne, we need to resolve the symbol, but that results in an overload resolution ambiguity, presumably because of not enough context.
olhotak
added a commit
to dotty-staging/dotty
that referenced
this issue
Jul 26, 2023
Compiler version
Scala compiler version 3.3.2-RC1-bin-SNAPSHOT-git-ce1ce99 -- Copyright 2002-2023, LAMP/EPFL
Minimized code
Compile with
scalac -Yexplicit-nulls
.Output
Expectation
Compiles.
The problem is that since
s
is of typeAnyRef | Null
, theeq
/ne
are actually extension methods inPredef
. The flow typing code looks for the patternl.eq(r)
andl.==(r)
but not the more complicated(Predef.eq(l))(r)
.The text was updated successfully, but these errors were encountered: