小编Nic*_*man的帖子

Scala 编译错误:未找到:类型 _$1

我正在研究 Scala 中的存在类型2.12.x。为此,我正在测试以下代码:

trait Parent
class ChildA extends Parent
class ChildB extends Parent

def whatIsInside(opt: Option[_ <: Parent]): String = {
  opt match {
    case _: Option[_ <: ChildA] => "ChildA"
    case _: Option[_ <: ChildB] => "ChildB"
    case _                      => throw new IllegalArgumentException("unknown type")
  }
}


whatIsInside(Some(new ChildA))
Run Code Online (Sandbox Code Playgroud)

由于类型擦除,我不希望这在运行时起作用,但是这甚至无法编译。我收到以下错误:

[error] ExistentialTypes.scala:12:24: not found: type _$2
[error]         case _: Option[_ <: ChildA] => "ChildA"
[error]                        ^
[error] ExistentialTypes.scala:13:24: not found: type _$3
[error]         case _: Option[_ …
Run Code Online (Sandbox Code Playgroud)

scala pattern-matching existential-type scalac scala-compiler

5
推荐指数
1
解决办法
368
查看次数