Open
Description
Compiler version
Scala compiler version 3.2.0-RC1-bin-SNAPSHOT-git-7fbbeef -- Copyright 2002-2022, LAMP/EPFL
Minimized code
Minimized from stdLib213/src/library/scala/collection/convert/JavaCollectionWrappers.scala
import language.unsafeNulls
trait Wrapper[K,V](val map: java.util.Map[K,V]):
def put(k: K, v: V): Option[V] =
val result = map.put(k, v)
Some(result)
Compile with scalac -Yexplicit-nulls Wrapper.scala
Output
-- [E007] Type Mismatch Error: Wrapper.scala:6:9 ------------------------------------------------------------------------------------------
6 | Some(result)
| ^^^^^^
| Found: (result : V | Null)
| Required: V
|
| longer explanation available when compiling with `-explain`
1 error found
Expectation
Should compile.
If result
is inlined as follows, it compiles:
Some(map.put(k, v))