Skip to content

Crash: class ...$CachedTypeRef cannot be cast to class ...$MethodType #18745

Closed
@soronpo

Description

@soronpo

Compiler version

v3.3.1 (also tested on nightly)

Minimized code

import scala.annotation.targetName

object Types:
  opaque type Color = Int
  object Color:
    def apply(i: Int): Color = i

  trait Surface
  opaque type Plane = (Int, Int) => Color

  object Plane:
    extension (plane: Plane)
      @targetName("zipWithP")
      def zipWith(that: Plane, f: (Color, Color) => Color): Plane = ???
      @targetName("zipWithS")
      def zipWith(that: Surface, f: (Color, Color) => Color): Surface = ???

import Types.*
import Plane.zipWith

@main def hello =
  val p: Plane = ???
  p.zipWith(p, (_: Color, _: Color) => Color(25)) 

Output (click arrow to expand)

Exception in thread "main" java.lang.ClassCastException: dotty.tools.dotc.core.Types$CachedTypeRef cannot be cast to dotty.tools.dotc.core.Types$MethodType
        at dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:297)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1481)
        at dotty.tools.dotc.transform.MacroTransform$Transformer.transform(MacroTransform.scala:40)
        at dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform$$anonfun$5(PostTyper.scala:381)
        at dotty.tools.dotc.transform.SuperAccessors.wrapDefDef(SuperAccessors.scala:223)
        at dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:381)
        at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.loop$2(tpd.scala:1228)
        at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1228)
        at dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transformStats(PostTyper.scala:488)
        at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformBlock(tpd.scala:1233)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1429)
        at dotty.tools.dotc.transform.MacroTransform$Transformer.transform(MacroTransform.scala:49)
        at dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:479)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform$$anonfun$1(Trees.scala:1510)
        at scala.collection.immutable.List.mapConserve(List.scala:472)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1510)
        at dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.app1$1(PostTyper.scala:317)
        at dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:331)
        at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformBlock$$anonfun$1$$anonfun$1(tpd.scala:1233)
        at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.loop$2(tpd.scala:1215)
        at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1228)
        at dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transformStats(PostTyper.scala:488)
        at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformBlock(tpd.scala:1233)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1429)
        at dotty.tools.dotc.transform.MacroTransform$Transformer.transform(MacroTransform.scala:49)
        at dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:479)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1481)
        at dotty.tools.dotc.transform.MacroTransform$Transformer.transform(MacroTransform.scala:40)
        at dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform$$anonfun$5(PostTyper.scala:381)
        at dotty.tools.dotc.transform.SuperAccessors.wrapDefDef(SuperAccessors.scala:223)
        at dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:381)
        at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.loop$2(tpd.scala:1228)
        at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1228)
        at dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transformStats(PostTyper.scala:488)
        at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1230)
        at dotty.tools.dotc.transform.MacroTransform$Transformer.transform(MacroTransform.scala:47)
        at dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform$$anonfun$4$$anonfun$1(PostTyper.scala:366)
        at dotty.tools.dotc.transform.SuperAccessors.wrapTemplate(SuperAccessors.scala:208)
        at dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform$$anonfun$4(PostTyper.scala:366)
        at dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.withNoCheckNews(PostTyper.scala:105)
        at dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:368)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1483)
        at dotty.tools.dotc.transform.MacroTransform$Transformer.transform(MacroTransform.scala:40)
        at dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:418)
        at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.loop$2(tpd.scala:1228)
        at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1228)
        at dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transformStats(PostTyper.scala:488)
        at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1230)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1491)
        at dotty.tools.dotc.transform.MacroTransform$Transformer.transform(MacroTransform.scala:40)
        at dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:479)
        at dotty.tools.dotc.transform.MacroTransform.run(MacroTransform.scala:18)
        at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:324)
        at scala.collection.immutable.List.map(List.scala:246)
        at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:328)
        at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:247)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1321)
        at dotty.tools.dotc.Run.runPhases$1(Run.scala:263)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:271)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:280)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:67)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:280)
        at dotty.tools.dotc.Run.compileSources(Run.scala:195)
        at dotty.tools.dotc.Run.compile(Run.scala:179)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:35)
        at dotty.tools.dotc.Driver.process(Driver.scala:195)
        at dotty.tools.dotc.Driver.process(Driver.scala:163)
        at dotty.tools.dotc.Driver.process(Driver.scala:175)
        at dotty.tools.dotc.Driver.main(Driver.scala:205)
        at dotty.tools.dotc.Main.main(Main.scala)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions