当我需要从具有完全相同类型的类结果返回时(不允许变化),我在 scala 中使用递归类型。
在将此模式与其他结构集成时,我遇到了一些问题。
提供的例子:
object Test {
trait Recursive[R <: Recursive[R]]
case class RecInt(data : Int) extends Recursive[RecInt]
case class RecFloat(data : Float) extends Recursive[RecFloat]
final case class ListHolder( rec : List[Recursive[_]] ) {
def get[R <: Recursive[R]](index : Int) : R = rec(index).asInstanceOf[R]
}
val lh = ListHolder(List( RecInt(1), RecFloat(1.5f) ))
val l0 : RecInt = lh.get(0)
final case class SingleHolder ( rec : Recursive[_] ) {
def get[R <: Recursive[R]] : R = rec.asInstanceOf[R]
}
}
给出错误输出
/home/ayvango/Work/scala/test/RecursiveContainer.scala:12: error: type arguments [_$2] do not conform to trait Recursive's type parameter bounds [R <: Main.$anon.Test.Recursive[R]]
final case class SingleHolder ( rec : Recursive[_] ) {
^
one error found
错误描述绝对清楚。
我应该如何指定类型边界以适应要求?
更新:
我需要隐藏类型信息。我可以只使用长度为 1 的列表来隐藏它。但是应该有等价的
我试过这种形式:
final case class SingleHolder ( rec : Recursive[T] forSome {type T <: Recursive[T]} ) {
def get[R <: Recursive[R]] : R = rec.asInstanceOf[R]
}
但收到此错误:
error: scala.tools.nsc.symtab.Types$TypeError: type mismatch;
found : Test.Recursive[(some other)_1(in method equals)] where type (some other)_1(in method equals) <: Test.Recursive[_0]
required: Test.Recursive[_ <: Test.Recursive[_0]]
at scala.tools.nsc.typechecker.Contexts$Context.error(Contexts.scala:298)
at scala.tools.nsc.typechecker.Infer$Inferencer.error(Infer.scala:207)
at scala.tools.nsc.typechecker.Infer$Inferencer.typeError(Infer.scala:217)
at scala.tools.nsc.typechecker.Infer$Inferencer.typeErrorTree(Infer.scala:232)
at scala.tools.nsc.typechecker.Typers$Typer.adapt(Typers.scala:936)
at scala.tools.nsc.typechecker.Typers$Typer.adapt(Typers.scala:719)
at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:4282)
at scala.tools.nsc.typechecker.Typers$Typer.typedArg(Typers.scala:2191)
at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$typedArgs$3.apply(Typers.scala:2204)
at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$typedArgs$3.apply(Typers.scala:2203)
at scala.Tuple3$Zipped$$anonfun$map$1.apply(Tuple3.scala:66)
at scala.Tuple3$Zipped$$anonfun$map$1.apply(Tuple3.scala:64)
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
at scala.collection.immutable.List.foreach(List.scala:76)
at scala.Tuple3$Zipped.map(Tuple3.scala:64)
at scala.tools.nsc.typechecker.Typers$Typer.typedArgs(Typers.scala:2203)
at scala.tools.nsc.typechecker.Typers$Typer.doTypedApply(Typers.scala:2423)
at scala.tools.nsc.typechecker.Typers$Typer.typedApply$1(Typers.scala:3373)
at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:4106)
at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:4273)
at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:4333)
at scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer$$anonfun$5.apply(ExplicitOuter.scala:400)
at scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer$$anonfun$5.apply(ExplicitOuter.scala:387)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:233)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:233)
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
at scala.collection.immutable.List.foreach(List.scala:76)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:233)
at scala.collection.immutable.List.map(List.scala:76)
at scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer.matchTranslation(ExplicitOuter.scala:387)
at scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer.transform(ExplicitOuter.scala:511)
at scala.tools.nsc.ast.Trees$Transformer$$anonfun$transformTrees$1.apply(Trees.scala:873)
at scala.tools.nsc.ast.Trees$Transformer$$anonfun$transformTrees$1.apply(Trees.scala:873)
at scala.collection.immutable.List.loop$1(List.scala:148)
at scala.collection.immutable.List.mapConserve(List.scala:164)
at scala.tools.nsc.ast.Trees$Transformer.transformTrees(Trees.scala:873)
at scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:837)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.transform(TypingTransformers.scala:53)
at scala.tools.nsc.transform.ExplicitOuter$OuterPathTransformer.transform(ExplicitOuter.scala:257)
at scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer.transform(ExplicitOuter.scala:521)
at scala.tools.nsc.ast.Trees$Transformer$$anonfun$transform$5.apply(Trees.scala:783)
at scala.tools.nsc.ast.Trees$Transformer$$anonfun$transform$5.apply(Trees.scala:781)
at scala.tools.nsc.ast.Trees$Transformer.atOwner(Trees.scala:899)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:38)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:31)
at scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:780)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.transform(TypingTransformers.scala:53)
at scala.tools.nsc.transform.ExplicitOuter$OuterPathTransformer.transform(ExplicitOuter.scala:257)
at scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer.transform(ExplicitOuter.scala:480)
at scala.tools.nsc.ast.Trees$Transformer$$anonfun$transformStats$1.apply(Trees.scala:891)
at scala.tools.nsc.ast.Trees$Transformer$$anonfun$transformStats$1.apply(Trees.scala:889)
at scala.collection.immutable.List.loop$1(List.scala:148)
at scala.collection.immutable.List.mapConserve(List.scala:164)
at scala.tools.nsc.ast.Trees$Transformer.transformStats(Trees.scala:889)
at scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:797)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.scala$tools$nsc$transform$TypingTransformers$TypingTransformer$$super$transform(TypingTransformers.scala:49)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer$$anonfun$transform$1.apply(TypingTransformers.scala:49)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer$$anonfun$transform$1.apply(TypingTransformers.scala:49)
at scala.tools.nsc.ast.Trees$Transformer.atOwner(Trees.scala:899)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:38)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:31)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.transform(TypingTransformers.scala:49)
at scala.tools.nsc.transform.ExplicitOuter$OuterPathTransformer.transform(ExplicitOuter.scala:257)
at scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer.transform(ExplicitOuter.scala:460)
at scala.tools.nsc.ast.Trees$Transformer.transformTemplate(Trees.scala:875)
at scala.tools.nsc.ast.Trees$Transformer$$anonfun$transform$2.apply(Trees.scala:767)
at scala.tools.nsc.ast.Trees$Transformer$$anonfun$transform$2.apply(Trees.scala:766)
at scala.tools.nsc.ast.Trees$Transformer.atOwner(Trees.scala:899)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:38)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:31)
at scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:765)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.transform(TypingTransformers.scala:53)
at scala.tools.nsc.transform.ExplicitOuter$OuterPathTransformer.transform(ExplicitOuter.scala:257)
at scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer.transform(ExplicitOuter.scala:521)
at scala.tools.nsc.ast.Trees$Transformer$$anonfun$transformStats$1.apply(Trees.scala:891)
at scala.tools.nsc.ast.Trees$Transformer$$anonfun$transformStats$1.apply(Trees.scala:889)
at scala.collection.immutable.List.loop$1(List.scala:148)
at scala.collection.immutable.List.mapConserve(List.scala:164)
at scala.tools.nsc.ast.Trees$Transformer.transformStats(Trees.scala:889)
at scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:797)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.scala$tools$nsc$transform$TypingTransformers$TypingTransformer$$super$transform(TypingTransformers.scala:49)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer$$anonfun$transform$1.apply(TypingTransformers.scala:49)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer$$anonfun$transform$1.apply(TypingTransformers.scala:49)
at scala.tools.nsc.ast.Trees$Transformer.atOwner(Trees.scala:899)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:38)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:31)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.transform(TypingTransformers.scala:49)
at scala.tools.nsc.transform.ExplicitOuter$OuterPathTransformer.transform(ExplicitOuter.scala:257)
at scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer.transform(ExplicitOuter.scala:460)
at scala.tools.nsc.ast.Trees$Transformer.transformTemplate(Trees.scala:875)
at scala.tools.nsc.ast.Trees$Transformer$$anonfun$transform$2.apply(Trees.scala:767)
at scala.tools.nsc.ast.Trees$Transformer$$anonfun$transform$2.apply(Trees.scala:766)
at scala.tools.nsc.ast.Trees$Transformer.atOwner(Trees.scala:899)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:38)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:31)
at scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:765)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.transform(TypingTransformers.scala:53)
at scala.tools.nsc.transform.ExplicitOuter$OuterPathTransformer.transform(ExplicitOuter.scala:257)
at scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer.transform(ExplicitOuter.scala:521)
at scala.tools.nsc.ast.Trees$Transformer$$anonfun$transformStats$1.apply(Trees.scala:891)
at scala.tools.nsc.ast.Trees$Transformer$$anonfun$transformStats$1.apply(Trees.scala:889)
at scala.collection.immutable.List.loop$1(List.scala:148)
at scala.collection.immutable.List.mapConserve(List.scala:164)
at scala.tools.nsc.ast.Trees$Transformer.transformStats(Trees.scala:889)
at scala.tools.nsc.ast.Trees$Transformer$$anonfun$transform$1.apply(Trees.scala:761)
at scala.tools.nsc.ast.Trees$Transformer$$anonfun$transform$1.apply(Trees.scala:761)
at scala.tools.nsc.ast.Trees$Transformer.atOwner(Trees.scala:899)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:38)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:31)
at scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:760)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.scala$tools$nsc$transform$TypingTransformers$TypingTransformer$$super$transform(TypingTransformers.scala:49)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer$$anonfun$transform$2.apply(TypingTransformers.scala:51)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer$$anonfun$transform$2.apply(TypingTransformers.scala:51)
at scala.tools.nsc.ast.Trees$Transformer.atOwner(Trees.scala:899)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:38)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:31)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.transform(TypingTransformers.scala:51)
at scala.tools.nsc.transform.ExplicitOuter$OuterPathTransformer.transform(ExplicitOuter.scala:257)
at scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer.transform(ExplicitOuter.scala:521)
at scala.tools.nsc.ast.Trees$Transformer.transformUnit(Trees.scala:892)
at scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer.scala$tools$nsc$transform$ExplicitOuter$ExplicitOuterTransformer$$super$transformUnit(ExplicitOuter.scala:529)
at scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer$$anonfun$transformUnit$1.apply(ExplicitOuter.scala:529)
at scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer$$anonfun$transformUnit$1.apply(ExplicitOuter.scala:529)
at scala.tools.nsc.symtab.SymbolTable.atPhase(SymbolTable.scala:95)
at scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer.transformUnit(ExplicitOuter.scala:529)
at scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer.transformUnit(ExplicitOuter.scala:318)
at scala.tools.nsc.transform.Transform$Phase.apply(Transform.scala:30)
at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:329)
at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:297)
at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:297)
at scala.collection.Iterator$class.foreach(Iterator.scala:772)
at scala.collection.mutable.ListBuffer$$anon$1.foreach(ListBuffer.scala:318)
at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:297)
at scala.tools.nsc.transform.ExplicitOuter$Phase.run(ExplicitOuter.scala:539)
at scala.tools.nsc.Global$Run.compileSources(Global.scala:953)
at scala.tools.nsc.Global$Run.compile(Global.scala:1041)
at scala.tools.nsc.Main$.process(Main.scala:106)
at scala.tools.nsc.Main$.main(Main.scala:123)
at scala.tools.nsc.Main.main(Main.scala)
Exception in thread "main" scala.tools.nsc.symtab.Types$TypeError: type mismatch;
found : Test.Recursive[(some other)_1(in method equals)] where type (some other)_1(in method equals) <: Test.Recursive[_0]
required: Test.Recursive[_ <: Test.Recursive[_0]]
at scala.tools.nsc.typechecker.Contexts$Context.error(Contexts.scala:298)
at scala.tools.nsc.typechecker.Infer$Inferencer.error(Infer.scala:207)
at scala.tools.nsc.typechecker.Infer$Inferencer.typeError(Infer.scala:217)
at scala.tools.nsc.typechecker.Infer$Inferencer.typeErrorTree(Infer.scala:232)
at scala.tools.nsc.typechecker.Typers$Typer.adapt(Typers.scala:936)
at scala.tools.nsc.typechecker.Typers$Typer.adapt(Typers.scala:719)
at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:4282)
at scala.tools.nsc.typechecker.Typers$Typer.typedArg(Typers.scala:2191)
at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$typedArgs$3.apply(Typers.scala:2204)
at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$typedArgs$3.apply(Typers.scala:2203)
at scala.Tuple3$Zipped$$anonfun$map$1.apply(Tuple3.scala:66)
at scala.Tuple3$Zipped$$anonfun$map$1.apply(Tuple3.scala:64)
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
at scala.collection.immutable.List.foreach(List.scala:76)
at scala.Tuple3$Zipped.map(Tuple3.scala:64)
at scala.tools.nsc.typechecker.Typers$Typer.typedArgs(Typers.scala:2203)
at scala.tools.nsc.typechecker.Typers$Typer.doTypedApply(Typers.scala:2423)
at scala.tools.nsc.typechecker.Typers$Typer.typedApply$1(Typers.scala:3373)
at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:4106)
at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:4273)
at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:4333)
at scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer$$anonfun$5.apply(ExplicitOuter.scala:400)
at scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer$$anonfun$5.apply(ExplicitOuter.scala:387)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:233)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:233)
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
at scala.collection.immutable.List.foreach(List.scala:76)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:233)
at scala.collection.immutable.List.map(List.scala:76)
at scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer.matchTranslation(ExplicitOuter.scala:387)
at scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer.transform(ExplicitOuter.scala:511)
at scala.tools.nsc.ast.Trees$Transformer$$anonfun$transformTrees$1.apply(Trees.scala:873)
at scala.tools.nsc.ast.Trees$Transformer$$anonfun$transformTrees$1.apply(Trees.scala:873)
at scala.collection.immutable.List.loop$1(List.scala:148)
at scala.collection.immutable.List.mapConserve(List.scala:164)
at scala.tools.nsc.ast.Trees$Transformer.transformTrees(Trees.scala:873)
at scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:837)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.transform(TypingTransformers.scala:53)
at scala.tools.nsc.transform.ExplicitOuter$OuterPathTransformer.transform(ExplicitOuter.scala:257)
at scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer.transform(ExplicitOuter.scala:521)
at scala.tools.nsc.ast.Trees$Transformer$$anonfun$transform$5.apply(Trees.scala:783)
at scala.tools.nsc.ast.Trees$Transformer$$anonfun$transform$5.apply(Trees.scala:781)
at scala.tools.nsc.ast.Trees$Transformer.atOwner(Trees.scala:899)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:38)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:31)
at scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:780)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.transform(TypingTransformers.scala:53)
at scala.tools.nsc.transform.ExplicitOuter$OuterPathTransformer.transform(ExplicitOuter.scala:257)
at scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer.transform(ExplicitOuter.scala:480)
at scala.tools.nsc.ast.Trees$Transformer$$anonfun$transformStats$1.apply(Trees.scala:891)
at scala.tools.nsc.ast.Trees$Transformer$$anonfun$transformStats$1.apply(Trees.scala:889)
at scala.collection.immutable.List.loop$1(List.scala:148)
at scala.collection.immutable.List.mapConserve(List.scala:164)
at scala.tools.nsc.ast.Trees$Transformer.transformStats(Trees.scala:889)
at scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:797)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.scala$tools$nsc$transform$TypingTransformers$TypingTransformer$$super$transform(TypingTransformers.scala:49)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer$$anonfun$transform$1.apply(TypingTransformers.scala:49)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer$$anonfun$transform$1.apply(TypingTransformers.scala:49)
at scala.tools.nsc.ast.Trees$Transformer.atOwner(Trees.scala:899)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:38)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:31)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.transform(TypingTransformers.scala:49)
at scala.tools.nsc.transform.ExplicitOuter$OuterPathTransformer.transform(ExplicitOuter.scala:257)
at scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer.transform(ExplicitOuter.scala:460)
at scala.tools.nsc.ast.Trees$Transformer.transformTemplate(Trees.scala:875)
at scala.tools.nsc.ast.Trees$Transformer$$anonfun$transform$2.apply(Trees.scala:767)
at scala.tools.nsc.ast.Trees$Transformer$$anonfun$transform$2.apply(Trees.scala:766)
at scala.tools.nsc.ast.Trees$Transformer.atOwner(Trees.scala:899)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:38)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:31)
at scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:765)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.transform(TypingTransformers.scala:53)
at scala.tools.nsc.transform.ExplicitOuter$OuterPathTransformer.transform(ExplicitOuter.scala:257)
at scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer.transform(ExplicitOuter.scala:521)
at scala.tools.nsc.ast.Trees$Transformer$$anonfun$transformStats$1.apply(Trees.scala:891)
at scala.tools.nsc.ast.Trees$Transformer$$anonfun$transformStats$1.apply(Trees.scala:889)
at scala.collection.immutable.List.loop$1(List.scala:148)
at scala.collection.immutable.List.mapConserve(List.scala:164)
at scala.tools.nsc.ast.Trees$Transformer.transformStats(Trees.scala:889)
at scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:797)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.scala$tools$nsc$transform$TypingTransformers$TypingTransformer$$super$transform(TypingTransformers.scala:49)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer$$anonfun$transform$1.apply(TypingTransformers.scala:49)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer$$anonfun$transform$1.apply(TypingTransformers.scala:49)
at scala.tools.nsc.ast.Trees$Transformer.atOwner(Trees.scala:899)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:38)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:31)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.transform(TypingTransformers.scala:49)
at scala.tools.nsc.transform.ExplicitOuter$OuterPathTransformer.transform(ExplicitOuter.scala:257)
at scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer.transform(ExplicitOuter.scala:460)
at scala.tools.nsc.ast.Trees$Transformer.transformTemplate(Trees.scala:875)
at scala.tools.nsc.ast.Trees$Transformer$$anonfun$transform$2.apply(Trees.scala:767)
at scala.tools.nsc.ast.Trees$Transformer$$anonfun$transform$2.apply(Trees.scala:766)
at scala.tools.nsc.ast.Trees$Transformer.atOwner(Trees.scala:899)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:38)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:31)
at scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:765)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.transform(TypingTransformers.scala:53)
at scala.tools.nsc.transform.ExplicitOuter$OuterPathTransformer.transform(ExplicitOuter.scala:257)
at scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer.transform(ExplicitOuter.scala:521)
at scala.tools.nsc.ast.Trees$Transformer$$anonfun$transformStats$1.apply(Trees.scala:891)
at scala.tools.nsc.ast.Trees$Transformer$$anonfun$transformStats$1.apply(Trees.scala:889)
at scala.collection.immutable.List.loop$1(List.scala:148)
at scala.collection.immutable.List.mapConserve(List.scala:164)
at scala.tools.nsc.ast.Trees$Transformer.transformStats(Trees.scala:889)
at scala.tools.nsc.ast.Trees$Transformer$$anonfun$transform$1.apply(Trees.scala:761)
at scala.tools.nsc.ast.Trees$Transformer$$anonfun$transform$1.apply(Trees.scala:761)
at scala.tools.nsc.ast.Trees$Transformer.atOwner(Trees.scala:899)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:38)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:31)
at scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:760)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.scala$tools$nsc$transform$TypingTransformers$TypingTransformer$$super$transform(TypingTransformers.scala:49)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer$$anonfun$transform$2.apply(TypingTransformers.scala:51)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer$$anonfun$transform$2.apply(TypingTransformers.scala:51)
at scala.tools.nsc.ast.Trees$Transformer.atOwner(Trees.scala:899)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:38)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:31)
at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.transform(TypingTransformers.scala:51)
at scala.tools.nsc.transform.ExplicitOuter$OuterPathTransformer.transform(ExplicitOuter.scala:257)
at scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer.transform(ExplicitOuter.scala:521)
at scala.tools.nsc.ast.Trees$Transformer.transformUnit(Trees.scala:892)
at scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer.scala$tools$nsc$transform$ExplicitOuter$ExplicitOuterTransformer$$super$transformUnit(ExplicitOuter.scala:529)
at scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer$$anonfun$transformUnit$1.apply(ExplicitOuter.scala:529)
at scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer$$anonfun$transformUnit$1.apply(ExplicitOuter.scala:529)
at scala.tools.nsc.symtab.SymbolTable.atPhase(SymbolTable.scala:95)
at scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer.transformUnit(ExplicitOuter.scala:529)
at scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer.transformUnit(ExplicitOuter.scala:318)
at scala.tools.nsc.transform.Transform$Phase.apply(Transform.scala:30)
at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:329)
at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:297)
at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:297)
at scala.collection.Iterator$class.foreach(Iterator.scala:772)
at scala.collection.mutable.ListBuffer$$anon$1.foreach(ListBuffer.scala:318)
at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:297)
at scala.tools.nsc.transform.ExplicitOuter$Phase.run(ExplicitOuter.scala:539)
at scala.tools.nsc.Global$Run.compileSources(Global.scala:953)
at scala.tools.nsc.Global$Run.compile(Global.scala:1041)
at scala.tools.nsc.Main$.process(Main.scala:106)
at scala.tools.nsc.Main$.main(Main.scala:123)
at scala.tools.nsc.Main.main(Main.scala)
我很好奇如何模拟与列表相同的行为