This code fails to compile with Result type in structural refinement may not refer to a user-defined value class
:
object Repro {
class Foo {}
case class Wrapper(val underlying: Int) extends AnyVal
def main(args: Array[String]): Unit = {
new Foo {
val w = Wrapper(1)
}
new Foo {} // Fails to compile if this line is present
}
}
/*
Compile error:
[error] Result type in structural refinement may not refer to a user-defined value class
[error] val w = Wrapper(1)
[error] ^
*/
However, if I remove the second new Foo
, then it compiles successfully:
object Repro {
class Foo {}
case class Wrapper(val underlying: Int) extends AnyVal
def main(args: Array[String]): Unit = {
new Foo {
val w = Wrapper(1)
}
// new Foo {} // Successfully compiles when this line is removed
}
}
Why does the second appearance of new Foo
cause a compile error? I am using Scala 2.13.14.