Skip to content
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

outer-reference from object inside def referencing local class crasher #15827

Closed
bishabosha opened this issue Aug 6, 2022 · 0 comments · Fixed by #16525
Closed

outer-reference from object inside def referencing local class crasher #15827

bishabosha opened this issue Aug 6, 2022 · 0 comments · Fixed by #16525

Comments

@bishabosha
Copy link
Member

bishabosha commented Aug 6, 2022

This is similar to code that would be generated for a Mirror - but I am using plain code to demonstrate that the problem is not to do with mirror synthesis itself.

derived from a shapeless test case at https://github.com/milessabin/shapeless/blob/ae9fc166082adb3fa590a604b256c9e87a467c56/core/src/test/scala/shapeless/generic.scala#L903

The crucial part is apparently the implementation of M_Rgb, and that it references TRgb - aka result of a match type.
If I replace TRgb by Inner.Rgb then it works.

Compiler version

3.2.1-RC1-bin-20220805-e560c2d-NIGHTLY

Minimized code

trait Mirr {
  type MirroredTp
  type Elems <: Tuple
}
trait MirrP extends Mirr {
  def fromProduct(x: Product): MirroredTp
}
trait MirrS extends Mirr

def outer3Local = {
  class Wrapper {
    object Nested {
      sealed trait Color
    }
  }
  val wrapper = new Wrapper
  import wrapper.Nested.Color

  object Inner {
    case object Red extends Color
    case object Green extends Color
    case object Blue extends Color
    case class Rgb(hex: Int) extends Color
    case object Rgb
  }

  object CallSite {
    def run =
      import Inner.*
      val M: (MirrS { type MirroredTp = Color; type Elems = (Inner.Red.type, Inner.Green.type, Inner.Blue.type, Inner.Rgb) }) =
        new MirrS {
          type MirroredTp = Color
          type Elems = (Inner.Red.type, Inner.Green.type, Inner.Blue.type, Inner.Rgb)
        }

      val M_Rgb =
        type TRgb = Tuple.Elem[M.Elems, 3]
        new MirrP {
          type MirroredTp = TRgb
          type Elems = Int *: EmptyTuple

          def fromProduct(x: Product): MirroredTp =
            new TRgb(x.productElement(0).asInstanceOf[Int])
        }: (MirrP {
          type MirroredTp = TRgb
          type Elems = Int *: EmptyTuple
        })
  }

  CallSite.run
}

@main def Test =
  outer3Local

Output (click arrow to expand)

exception occurred while compiling tests/run/i13332shapeless-c.scala
Exception in thread "main" java.lang.AssertionError: assertion failed: asTerm called on not-a-Term val <none>
	at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
	at dotty.tools.dotc.core.Symbols$Symbol.asTerm(Symbols.scala:169)
	at dotty.tools.dotc.transform.ExplicitOuter$.dotty$tools$dotc$transform$ExplicitOuter$$$outerParamAccessor(ExplicitOuter.scala:230)
	at dotty.tools.dotc.transform.ExplicitOuter$OuterOps$.loop$1(ExplicitOuter.scala:438)
	at dotty.tools.dotc.transform.ExplicitOuter$OuterOps$.path$extension(ExplicitOuter.scala:447)
	at dotty.tools.dotc.transform.LambdaLift$Lifter.memberRef(LambdaLift.scala:161)
	at dotty.tools.dotc.transform.LambdaLift$Lifter.proxyRef(LambdaLift.scala:167)
	at dotty.tools.dotc.transform.LambdaLift$Lifter.addFreeArgs$$anonfun$1(LambdaLift.scala:172)
	at scala.collection.immutable.List.map(List.scala:246)
	at dotty.tools.dotc.transform.LambdaLift$Lifter.addFreeArgs(LambdaLift.scala:172)
	at dotty.tools.dotc.transform.LambdaLift.transformApply(LambdaLift.scala:310)
	at dotty.tools.dotc.transform.LambdaLift.transformApply(LambdaLift.scala:309)
	at dotty.tools.dotc.transform.MegaPhase.goApply(MegaPhase.scala:650)
	at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:280)
	at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:427)
	at dotty.tools.dotc.transform.MegaPhase.recur$1(MegaPhase.scala:459)
	at dotty.tools.dotc.transform.MegaPhase.transformTrees(MegaPhase.scala:459)
	at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:279)
	at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:427)
	at dotty.tools.dotc.transform.MegaPhase.mapDefDef$1(MegaPhase.scala:248)
	at dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:251)
	at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:425)
	at dotty.tools.dotc.transform.MegaPhase.loop$1(MegaPhase.scala:438)
	at dotty.tools.dotc.transform.MegaPhase.transformStats(MegaPhase.scala:438)
	at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:359)
	at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:427)
	at dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:255)
	at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:425)
	at dotty.tools.dotc.transform.MegaPhase.loop$2(MegaPhase.scala:444)
	at dotty.tools.dotc.transform.MegaPhase.transformBlock(MegaPhase.scala:449)
	at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:298)
	at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:427)
	at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:320)
	at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:427)
	at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:320)
	at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:427)
	at dotty.tools.dotc.transform.MegaPhase.loop$2(MegaPhase.scala:447)
	at dotty.tools.dotc.transform.MegaPhase.transformBlock(MegaPhase.scala:449)
	at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:298)
	at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:427)
	at dotty.tools.dotc.transform.MegaPhase.mapValDef$1(MegaPhase.scala:234)
	at dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:239)
	at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:425)
	at dotty.tools.dotc.transform.MegaPhase.loop$2(MegaPhase.scala:444)
	at dotty.tools.dotc.transform.MegaPhase.transformBlock(MegaPhase.scala:449)
	at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:298)
	at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:427)
	at dotty.tools.dotc.transform.MegaPhase.mapDefDef$1(MegaPhase.scala:248)
	at dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:251)
	at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:425)
	at dotty.tools.dotc.transform.MegaPhase.loop$1(MegaPhase.scala:438)
	at dotty.tools.dotc.transform.MegaPhase.transformStats(MegaPhase.scala:438)
	at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:359)
	at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:427)
	at dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:255)
	at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:425)
	at dotty.tools.dotc.transform.MegaPhase.loop$2(MegaPhase.scala:444)
	at dotty.tools.dotc.transform.MegaPhase.transformBlock(MegaPhase.scala:449)
	at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:298)
	at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:427)
	at dotty.tools.dotc.transform.MegaPhase.mapDefDef$1(MegaPhase.scala:248)
	at dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:251)
	at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:425)
	at dotty.tools.dotc.transform.MegaPhase.loop$1(MegaPhase.scala:438)
	at dotty.tools.dotc.transform.MegaPhase.transformStats(MegaPhase.scala:438)
	at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:359)
	at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:427)
	at dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:255)
	at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:425)
	at dotty.tools.dotc.transform.MegaPhase.loop$1(MegaPhase.scala:438)
	at dotty.tools.dotc.transform.MegaPhase.transformStats(MegaPhase.scala:438)
	at dotty.tools.dotc.transform.MegaPhase.mapPackage$1(MegaPhase.scala:379)
	at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:382)
	at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:427)
	at dotty.tools.dotc.transform.MegaPhase.transformUnit(MegaPhase.scala:454)
	at dotty.tools.dotc.transform.MegaPhase.run(MegaPhase.scala:466)
	at dotty.tools.dotc.transform.MegaPhase$MiniPhase.run(MegaPhase.scala:131)
	at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:311)
	at scala.collection.immutable.List.map(List.scala:246)
	at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:312)
	at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:234)
	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:1328)
	at dotty.tools.dotc.Run.runPhases$1(Run.scala:245)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:253)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:262)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:68)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:262)
	at dotty.tools.dotc.Run.compileSources(Run.scala:186)
	at dotty.tools.dotc.Run.compile(Run.scala:170)
	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)
java.lang.AssertionError: assertion failed: asTerm called on not-a-Term val <none> while compiling tests/run/i13332shapeless-c.scala
@Kordyjan Kordyjan added this to the Future versions milestone Dec 12, 2022
@odersky odersky self-assigned this Dec 14, 2022
odersky added a commit to dotty-staging/dotty that referenced this issue Dec 14, 2022
little-inferno pushed a commit to little-inferno/dotty that referenced this issue Jan 25, 2023
@Kordyjan Kordyjan modified the milestones: Future versions, 3.3.0 Aug 1, 2023
EugeneFlesselle added a commit to dotty-staging/dotty that referenced this issue Apr 14, 2024
Test scala#15827 with a classpath dependency
EugeneFlesselle added a commit to dotty-staging/dotty that referenced this issue Apr 14, 2024
Test scala#15827 with a classpath dependency
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants