Closed
Description
object Foo {
(new Function0[Unit] {
def apply() = println("hello")
})()
}
Note that this does not fail if the apply
method is written explicitly.
Exception in thread "main" java.lang.Error: unexpected type.
fun = Block(List(TypeDef($anon,Template(DefDef(<init>,List(),List(List()),TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,scala)),Unit)],EmptyTree),List(Apply(Select(New(TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,lang)),Object)]),<init>),List()), AppliedTypeTree(Ident(Function0),List(Ident(Unit)))),ValDef(_,EmptyTree,EmptyTree),List(DefDef(apply,List(),List(List()),TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,$anon)),scala$Function0$$R)],Apply(Ident(println),List(Literal(Constant(hello))))))))),Typed(Select(Apply(Select(New(Ident($anon)),<init>),List()),apply),TypeTree[MethodType(List(), List(), TypeRef(TermRef(ThisType(TypeRef(NoPrefix,<root>)),scala),Unit))])),
methPart(fun) = Typed(Select(Apply(Select(New(Ident($anon)),<init>),List()),apply),TypeTree[MethodType(List(), List(), TypeRef(TermRef(ThisType(TypeRef(NoPrefix,<root>)),scala),Unit))]),
methPart(fun).tpe = MethodType(List(), List(), TypeRef(TermRef(ThisType(TypeRef(NoPrefix,<root>)),scala),Unit)),
tpe = MethodType(List(), List(), TypeRef(TermRef(ThisType(TypeRef(NoPrefix,<root>)),scala),Unit))
at dotty.tools.dotc.typer.Applications$class.handleUnexpectedFunType(Applications.scala:661)
at dotty.tools.dotc.typer.Typer.handleUnexpectedFunType(Typer.scala:60)
at dotty.tools.dotc.typer.Applications$$anonfun$realApply$1$1.dotty$tools$dotc$typer$Applications$class$$anonfun$$simpleApply$1(Applications.scala:577)
at dotty.tools.dotc.typer.Applications$$anonfun$realApply$1$1$$anonfun$apply$5.apply(Applications.scala:603)
at dotty.tools.dotc.typer.Applications$$anonfun$realApply$1$1$$anonfun$apply$5.apply(Applications.scala:603)
at dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:1472)
at dotty.tools.dotc.typer.Applications$$anonfun$realApply$1$1.apply(Applications.scala:604)
at dotty.tools.dotc.typer.Applications$$anonfun$realApply$1$1.apply(Applications.scala:544)
at dotty.tools.dotc.util.Stats$.track(Stats.scala:36)
at dotty.tools.dotc.typer.Applications$class.realApply$1(Applications.scala:544)
at dotty.tools.dotc.typer.Applications$class.typedApply(Applications.scala:647)
at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:60)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1376)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1417)
at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1427)
at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1425)
at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:155)
at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:56)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1425)
at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1455)
at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1460)
at dotty.tools.dotc.typer.Typer$$anonfun$typedClassDef$1.apply(Typer.scala:1196)
at dotty.tools.dotc.typer.Typer$$anonfun$typedClassDef$1.apply(Typer.scala:1144)
at dotty.tools.dotc.util.Stats$.track(Stats.scala:36)
at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:1144)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1367)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1415)
at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1427)
at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1425)
at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:155)
at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:56)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1425)
at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1449)
at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1460)
at dotty.tools.dotc.typer.Typer$$anonfun$typedPackageDef$1.apply(Typer.scala:1292)
at dotty.tools.dotc.typer.Typer$$anonfun$typedPackageDef$1.apply(Typer.scala:1283)
at dotty.tools.dotc.util.Stats$.track(Stats.scala:36)
at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:1283)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1405)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1417)
at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1427)
at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1425)
at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:155)
at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:56)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1425)
at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:1464)
at dotty.tools.dotc.typer.FrontEnd$$anonfun$typeCheck$1.apply$mcV$sp(FrontEnd.scala:47)
at dotty.tools.dotc.typer.FrontEnd.monitor(FrontEnd.scala:23)
at dotty.tools.dotc.typer.FrontEnd.typeCheck(FrontEnd.scala:45)
at dotty.tools.dotc.typer.FrontEnd$$anonfun$runOn$3.apply(FrontEnd.scala:69)
at dotty.tools.dotc.typer.FrontEnd$$anonfun$runOn$3.apply(FrontEnd.scala:69)
at scala.collection.immutable.List.foreach(List.scala:381)
at dotty.tools.dotc.typer.FrontEnd.runOn(FrontEnd.scala:69)
at dotty.tools.dotc.Run$$anonfun$compileUnits$1$$anonfun$apply$mcV$sp$1.apply(Run.scala:69)
at dotty.tools.dotc.Run$$anonfun$compileUnits$1$$anonfun$apply$mcV$sp$1.apply(Run.scala:66)
at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:186)
at dotty.tools.dotc.Run$$anonfun$compileUnits$1.apply$mcV$sp(Run.scala:66)
at dotty.tools.dotc.Run$$anonfun$compileUnits$1.apply(Run.scala:60)
at dotty.tools.dotc.Run$$anonfun$compileUnits$1.apply(Run.scala:60)
at dotty.tools.dotc.util.Stats$.monitorHeartBeat(Stats.scala:69)
at dotty.tools.dotc.Run.compileUnits(Run.scala:60)
at dotty.tools.dotc.Run.compileSources(Run.scala:57)
at dotty.tools.dotc.Run.compile(Run.scala:41)
at dotty.tools.dotc.Driver.doCompile(Driver.scala:26)
at dotty.tools.dotc.Driver.process(Driver.scala:124)
at dotty.tools.dotc.Driver.process(Driver.scala:93)
at dotty.tools.dotc.Driver.process(Driver.scala:105)
at dotty.tools.dotc.Driver.main(Driver.scala:132)
at dotty.tools.dotc.Main.main(Main.scala)