Skip to content

crash with message: "Apply cannot be cast to.." #1641

Closed
@helloqirun

Description

@helloqirun

dotc crashes when compiling the following code.

$ cat abc.scala

package bar { object bippy extends (Double => String) { def apply(x: Double): String = "Double" } }
package object println { def bippy(x: Int, y: Int, z: Int) = "(Int, Int, Int)" }
object Test {
  def main(args: Array[String]): Unit = {
    println(bar.bippy(5.5))
    println(bar.bippy(1, 2, 3))
  }
}

$ dotc abc.scala

-- Error: abc.scala ----------------------------------------------------------------------------------------------------
  |^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |method println is already defined, cannot be a package
2 |package object println { def bippy(x: Int, y: Int, z: Int) = "(Int, Int, Int)" }

exception occurred while typechecking abc.scala

exception occurred while compiling abc.scala
Exception in thread "main" java.lang.ClassCastException: dotty.tools.dotc.ast.Trees$Apply cannot be cast to dotty.tools.dotc.ast.Trees$RefTree
    at dotty.tools.dotc.typer.Typer$$anonfun$typedPackageDef$1.apply(Typer.scala:1347)
    at dotty.tools.dotc.typer.Typer$$anonfun$typedPackageDef$1.apply(Typer.scala:1337)
    at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
    at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:1337)
    at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1468)
    at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1480)
    at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1490)
    at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1488)
    at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:132)
    at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:57)
    at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1488)
    at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1523)
    at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1528)
    at dotty.tools.dotc.typer.Typer$$anonfun$typedPackageDef$1.apply(Typer.scala:1346)
    at dotty.tools.dotc.typer.Typer$$anonfun$typedPackageDef$1.apply(Typer.scala:1337)
    at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
    at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:1337)
    at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1468)
    at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1480)
    at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1490)
    at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1488)
    at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:132)
    at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:57)
    at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1488)
    at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:1540)
    at dotty.tools.dotc.typer.FrontEnd$$anonfun$typeCheck$1.apply$mcV$sp(FrontEnd.scala:50)
    at dotty.tools.dotc.typer.FrontEnd.monitor(FrontEnd.scala:24)
    at dotty.tools.dotc.typer.FrontEnd.typeCheck(FrontEnd.scala:48)
    at dotty.tools.dotc.typer.FrontEnd$$anonfun$runOn$3.apply(FrontEnd.scala:72)
    at dotty.tools.dotc.typer.FrontEnd$$anonfun$runOn$3.apply(FrontEnd.scala:72)
    at scala.collection.immutable.List.foreach(List.scala:381)
    at dotty.tools.dotc.typer.FrontEnd.runOn(FrontEnd.scala:72)
    at dotty.tools.dotc.Run$$anonfun$compileUnits$1$$anonfun$apply$mcV$sp$1.apply(Run.scala:75)
    at dotty.tools.dotc.Run$$anonfun$compileUnits$1$$anonfun$apply$mcV$sp$1.apply(Run.scala:72)
    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:72)
    at dotty.tools.dotc.Run$$anonfun$compileUnits$1.apply(Run.scala:66)
    at dotty.tools.dotc.Run$$anonfun$compileUnits$1.apply(Run.scala:66)
    at dotty.tools.dotc.util.Stats$.monitorHeartBeat(Stats.scala:76)
    at dotty.tools.dotc.Run.compileUnits(Run.scala:66)
    at dotty.tools.dotc.Run.compileSources(Run.scala:63)
    at dotty.tools.dotc.Run.compile(Run.scala:47)
    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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions