Open
Description
Compiler version
Scala 3.7.1
The issue also exists on 3.3.5 and 3.6.4, which very likely implies that the issue exists on every version.
Notably, compiler with version less than 3.7 encounter additional bugs related on union type on top of the current bug.
JVM version is not related to the problem. Nor is the running environment.
Affected Component
The compiler itself.
Minimized code
enum E:
case A
case B
case C
type NotC = E.A.type | E.B.type
def doSomething(): (Int, NotC) = (1, E.A)
def bee(nu: NotC): Unit =
println("bee")
@main def main(): Unit =
val nu = doSomething()
val (x, nnu) = nu
bee(nnu)
Output
Compiling project (Scala 3.7.1, JVM (24))
[error] ./main.scala:16:9
[error] Found: (nnu : E)
[error] Required: NotC
[error] bee(nnu)
[error] ^^^
Error compiling project (Scala 3.7.1, JVM (24))
Compilation failed
Expectation
bee
Additioinal Note
Please see here: https://www.reddit.com/r/scala/comments/1l5cpg4/weird_behavior_of_union_type_widening_on_method/
for a full discussion regarding the issue.
I kept the bug report as minimal as possible as instructed, but the context might be helpful.