def foo(x: AnyRef): Unit =
println(x)
@main def main(): Unit =
foo(10)
File2:
def foo(x: AnyRef | Null): Unit =
println(x)
@main def main(): Unit =
foo(10)
Output
File1:
-- [E007] Type Mismatch Error: Main.scala:5:6 ----------------------------------
5 | foo(10)
| ^^
|Found: (10 : Int)
|Required: AnyRef
|Note that implicit conversions were not tried because the result of an implicit conversion
|must be more specific than AnyRef
|
| longer explanation available when compiling with `-explain`
1 error found
File2: passed compilation.
Expectation
File2 should fail compilation as well because AnyRef | Null is not more specific than AnyRef.
Compiler version
3.4.2
Minimized code
File1:
File2:
Output
File1:
File2: passed compilation.
Expectation
File2 should fail compilation as well because
AnyRef | Null
is not more specific thanAnyRef
.