Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
soronpo opened this issue Oct 22, 2023 · 2 comments · Fixed by #18759
Closed

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

soronpo opened this issue Oct 22, 2023 · 2 comments · Fixed by #18759

Comments

@soronpo
Copy link
Contributor

soronpo commented Oct 22, 2023

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)
@nicolasstucki
Copy link
Contributor

Minimized

object Color:
  def apply(i: Int): Int = i

type Plane

object Plane:
  extension (plane: Plane)
    def zipWith(that: String, f: Int => Int): Int = ???
    def zipWith(that: Int, f: Int => Int): Int = ???

import Plane.zipWith

def test(p: Plane) =
  p.zipWith("", (_: Int) => Color(25))

@nicolasstucki
Copy link
Contributor

This fails Ychecking after typer

Exception in thread "main" dotty.tools.dotc.reporting.UnhandledError: object Color: Color does not take parameters

  exception while retyping Plane.zipWith(p)("",
  {
    def $anonfun(_$1: Int): <error unspecified error> = Color()
    closure($anonfun)
  }
) of class Apply # -1

@odersky odersky self-assigned this Oct 23, 2023
odersky added a commit to dotty-staging/dotty that referenced this issue Oct 23, 2023
…ding resolution

The SynthesizeExtMethodReceiver mode is supposed to be turned on only for the
direct application of of a synthesized receiver to the qualifier of an
extension method selection. previously its lifetime was accidentally extended
when overloading resolution looking at subsequent parameter lists because the
first one was not enough to disambiguate.

Fixes scala#18745
Fixes scala#18744
WojciechMazur pushed a commit that referenced this issue Jun 22, 2024
…ding resolution

The SynthesizeExtMethodReceiver mode is supposed to be turned on only for the
direct application of of a synthesized receiver to the qualifier of an
extension method selection. previously its lifetime was accidentally extended
when overloading resolution looking at subsequent parameter lists because the
first one was not enough to disambiguate.

Fixes #18745
Fixes #18744

[Cherry-picked edc4bc8]
WojciechMazur pushed a commit that referenced this issue Jun 23, 2024
…ding resolution

The SynthesizeExtMethodReceiver mode is supposed to be turned on only for the
direct application of of a synthesized receiver to the qualifier of an
extension method selection. previously its lifetime was accidentally extended
when overloading resolution looking at subsequent parameter lists because the
first one was not enough to disambiguate.

Fixes #18745
Fixes #18744

[Cherry-picked edc4bc8]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants