Skip to content

MatchError at GenBCode with class wrapping java style enum #9579

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
bishabosha opened this issue Aug 18, 2020 · 1 comment · Fixed by #9678
Closed

MatchError at GenBCode with class wrapping java style enum #9579

bishabosha opened this issue Aug 18, 2020 · 1 comment · Fixed by #9678

Comments

@bishabosha
Copy link
Member

Minimized code

class Container : // needs to be wrapped in a class
  enum Color extends java.lang.Enum[Color]:
    case Red, Green, Blue

Output (click arrow to expand)

an unexpected type representation reached the compiler backend while compiling Container.scala: MethodType(List(), List(), TypeRef(ThisType(TypeRef(ThisType(TypeRef(NoPrefix,module class <empty>)),class Container)),class Container$Color)). If possible, please file a bug on https://github.com/lampepfl/dotty/issues
Error while emitting Container.scala
exception occurred while compiling Container.scala
scala.MatchError: MethodType(List(), List(), TypeRef(ThisType(TypeRef(ThisType(TypeRef(NoPrefix,module class <empty>)),class Container)),class Container$Color)) (of class dotty.tools.dotc.core.Types$CachedMethodType) while compiling Container.scala
Exception in thread "main" scala.MatchError: MethodType(List(), List(), TypeRef(ThisType(TypeRef(ThisType(TypeRef(NoPrefix,module class <empty>)),class Container)),class Container$Color)) (of class dotty.tools.dotc.core.Types$CachedMethodType)
	at dotty.tools.backend.jvm.BCodeHelpers.dotty$tools$backend$jvm$BCodeHelpers$$typeToTypeKind(BCodeHelpers.scala:850)
	at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.toTypeKind(BCodeHelpers.scala:299)
	at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.toTypeKind$(BCodeHelpers.scala:210)
	at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.toTypeKind(BCodeSkelBuilder.scala:58)
	at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.symInfoTK(BCodeSkelBuilder.scala:87)
	at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.addClassFields$$anonfun$2(BCodeSkelBuilder.scala:268)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:333)
	at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.addClassFields(BCodeSkelBuilder.scala:274)
	at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.genPlainClass(BCodeSkelBuilder.scala:134)
	at dotty.tools.backend.jvm.GenBCodePipeline$Worker1.visit(GenBCode.scala:224)
	at dotty.tools.backend.jvm.GenBCodePipeline$Worker1.run(GenBCode.scala:191)
	at dotty.tools.backend.jvm.GenBCodePipeline.buildAndSendToDisk(GenBCode.scala:521)
	at dotty.tools.backend.jvm.GenBCodePipeline.run(GenBCode.scala:487)
	at dotty.tools.backend.jvm.GenBCode.run(GenBCode.scala:57)
	at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:295)
	at scala.collection.immutable.List.map(List.scala:246)
	at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:296)
	at dotty.tools.backend.jvm.GenBCode.runOn(GenBCode.scala:61)
	at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:181)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
	at dotty.tools.dotc.Run.runPhases$5(Run.scala:191)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:199)
	at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:64)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:206)
	at dotty.tools.dotc.Run.compileSources(Run.scala:143)
	at dotty.tools.dotc.Run.compile(Run.scala:125)
	at dotty.tools.dotc.Driver.doCompile(Driver.scala:38)
	at dotty.tools.dotc.Driver.process(Driver.scala:195)
	at dotty.tools.dotc.Driver.process(Driver.scala:164)
	at dotty.tools.dotc.Driver.process(Driver.scala:176)
	at dotty.tools.dotc.Driver.main(Driver.scala:203)
	at dotty.tools.dotc.Main.main(Main.scala)

Notes

with -Ycheck:completeJavaEnums we get the assertion failure: "non member selection of getter Red in object Color from Container.this.Color.type in Color.this.$outer.Color.Red while compiling Container.scala"

checking Container.scala after phase MegaPhase{elimErasedValueType, pureStats, vcElideAllocations, arrayApply, elimPolyFunction, tailrec, completeJavaEnums, mixin, lazyVals, memoize, nonLocalReturns, capturedVars}
exception while typing @scala.annotation.static() <static> val Red: (): Container.this.Color = 
  Color.this.$outer.Color.Red of class class dotty.tools.dotc.ast.Trees$ValDef # 2002
exception while typing @scala.annotation.internal.Child[
  (Container.Color.Blue : (): Container.this.Color)
]() @scala.annotation.internal.Child[
  (Container.Color.Green : (): Container.this.Color)
]() @scala.annotation.internal.Child[
  (Container.Color.Red : (): Container.this.Color)
]() sealed abstract class Color($outer: Container, _$name: String, 
  _$ordinal: Int
) extends Enum, Enum {
  super(Color.this._$name, Color.this._$ordinal)
  def productIterator(): scala.collection.Iterator = 
    super[Product].productIterator()
  def productPrefix(): String = super[Product].productPrefix()
  def productElementName(n: Int): String = super[Product].productElementName(n)
  def productElementNames(): scala.collection.Iterator = 
    super[Product].productElementNames()
  private val $outer: Container
  val _$name: String
  val _$ordinal: Int
  @scala.annotation.static() <static> val Red: (): Container.this.Color = 
    Color.this.$outer.Color.Red
  @scala.annotation.static() <static> val Green: (): Container.this.Color = 
    Color.this.$outer.Color.Green
  @scala.annotation.static() <static> val Blue: (): Container.this.Color = 
    Color.this.$outer.Color.Blue
  final def Container$Color$$$outer(): Container = Color.this.$outer
} of class class dotty.tools.dotc.ast.Trees$TypeDef # 2064
exception while typing @scala.annotation.internal.SourceFile("Container.scala") class Container()
   extends
 Object {
  super()
  @scala.annotation.internal.Child[
    (Container.Color.Blue : (): Container.this.Color)
  ]() @scala.annotation.internal.Child[
    (Container.Color.Green : (): Container.this.Color)
  ]() @scala.annotation.internal.Child[
    (Container.Color.Red : (): Container.this.Color)
  ]() sealed abstract class Color($outer: Container, _$name: String, 
    _$ordinal: Int
  ) extends Enum, Enum {
    super(Color.this._$name, Color.this._$ordinal)
    def productIterator(): scala.collection.Iterator = 
      super[Product].productIterator()
    def productPrefix(): String = super[Product].productPrefix()
    def productElementName(n: Int): String = 
      super[Product].productElementName(n)
    def productElementNames(): scala.collection.Iterator = 
      super[Product].productElementNames()
    private val $outer: Container
    val _$name: String
    val _$ordinal: Int
    @scala.annotation.static() <static> val Red: (): Container.this.Color = 
      Color.this.$outer.Color.Red
    @scala.annotation.static() <static> val Green: (): Container.this.Color = 
      Color.this.$outer.Color.Green
    @scala.annotation.static() <static> val Blue: (): Container.this.Color = 
      Color.this.$outer.Color.Blue
    final def Container$Color$$$outer(): Container = Color.this.$outer
  }
  val Color$lzy1: Container.this.Color$ = new Container.this.Color$(this)
  final lazy module def Color(): Container.this.Color$ = this.Color$lzy1
  final module class Color$($outer: Container) extends Object, 
    java.io.Serializable
  , scala.deriving.Mirror.Sum {
    super()
    def values(): Container.this.Color[] = 
      this.$values.values().toArray(
        scala.reflect.ClassTag.apply(classOf[Container.this.Color])
      ).asInstanceOf[Container.this.Color[]]
    private val $values: scala.runtime.EnumValues = 
      new scala.runtime.EnumValues()
    def valueOf($name: String): Container.this.Color = 
      try 
        this.$values.fromName().apply($name).asInstanceOf[Container.this.Color]
       catch 
        {
          case ex$ @ _:java.util.NoSuchElementException => 
            throw new IllegalArgumentException("key not found: ".concat($name))
        }
    private def $new(_$ordinal: Int, $name: String): Container.this.Color = 
      {
        final class $anon($outer: Container.this.Color$) extends 
          Container.this.Color
        , scala.runtime.EnumValue, scala.deriving.Mirror.Singleton {
          super(this.$outer.Container$Color$$$$outer(), $name, _$ordinal)
          override def canEqual(that: Object): Boolean = 
            super[EnumValue].canEqual(that)
          override def productArity(): Int = super[EnumValue].productArity()
          override def productPrefix(): String = 
            super[EnumValue].productPrefix()
          override def productElement(n: Int): Object = 
            super[EnumValue].productElement(n)
          override def productElementName(n: Int): String = 
            super[EnumValue].productElementName(n)
          def fromProduct(p: Product): scala.deriving.Mirror.Singleton = 
            super[Singleton].fromProduct(p)
          def $ordinal(): Int = _$ordinal
          override def toString(): String = $name
          this.$outer.$values.register(this)
          private val $outer: Container.this.Color$
          final def Container$Color$_$$anon$$$outer(): Container.this.Color$ = 
            $outer
          def fromProduct(p: Product): Object = this.fromProduct(p)
        }
        new 
          Container.this.Color with scala.runtime.EnumValue with 
            scala.deriving.Mirror.Singleton
           {...}
        (this):Container.this.Color
      }
    private val Red: Container.this.Color = this.$new(0, "Red")
    case def Red(): Container.this.Color = this.Red
    private val Green: Container.this.Color = this.$new(1, "Green")
    case def Green(): Container.this.Color = this.Green
    private val Blue: Container.this.Color = this.$new(2, "Blue")
    case def Blue(): Container.this.Color = this.Blue
    def ordinal(x$0: Container.this.Color): Int = x$0.ordinal()
    private val $outer: Container
    final def Container$Color$$$$outer(): Container = Container.Color.$outer
    def ordinal(x: Object): Int = 
      this.ordinal(x.asInstanceOf[Container.this.Color])
  }
} of class class dotty.tools.dotc.ast.Trees$TypeDef # 2187
exception while typing package <empty> {
  @scala.annotation.internal.SourceFile("Container.scala") class Container()
     extends
   Object {
    super()
    @scala.annotation.internal.Child[
      (Container.Color.Blue : (): Container.this.Color)
    ]() @scala.annotation.internal.Child[
      (Container.Color.Green : (): Container.this.Color)
    ]() @scala.annotation.internal.Child[
      (Container.Color.Red : (): Container.this.Color)
    ]() sealed abstract class Color($outer: Container, _$name: String, 
      _$ordinal: Int
    ) extends Enum, Enum {
      super(Color.this._$name, Color.this._$ordinal)
      def productIterator(): scala.collection.Iterator = 
        super[Product].productIterator()
      def productPrefix(): String = super[Product].productPrefix()
      def productElementName(n: Int): String = 
        super[Product].productElementName(n)
      def productElementNames(): scala.collection.Iterator = 
        super[Product].productElementNames()
      private val $outer: Container
      val _$name: String
      val _$ordinal: Int
      @scala.annotation.static() <static> val Red: (): Container.this.Color = 
        Color.this.$outer.Color.Red
      @scala.annotation.static() <static> val Green: (): Container.this.Color = 
        Color.this.$outer.Color.Green
      @scala.annotation.static() <static> val Blue: (): Container.this.Color = 
        Color.this.$outer.Color.Blue
      final def Container$Color$$$outer(): Container = Color.this.$outer
    }
    val Color$lzy1: Container.this.Color$ = new Container.this.Color$(this)
    final lazy module def Color(): Container.this.Color$ = this.Color$lzy1
    final module class Color$($outer: Container) extends Object, 
      java.io.Serializable
    , scala.deriving.Mirror.Sum {
      super()
      def values(): Container.this.Color[] = 
        this.$values.values().toArray(
          scala.reflect.ClassTag.apply(classOf[Container.this.Color])
        ).asInstanceOf[Container.this.Color[]]
      private val $values: scala.runtime.EnumValues = 
        new scala.runtime.EnumValues()
      def valueOf($name: String): Container.this.Color = 
        try 
          this.$values.fromName().apply($name).asInstanceOf[Container.this.Color
            ]
         catch 
          {
            case ex$ @ _:java.util.NoSuchElementException => 
              throw 
                new IllegalArgumentException("key not found: ".concat($name))
          }
      private def $new(_$ordinal: Int, $name: String): Container.this.Color = 
        {
          final class $anon($outer: Container.this.Color$) extends 
            Container.this.Color
          , scala.runtime.EnumValue, scala.deriving.Mirror.Singleton {
            super(this.$outer.Container$Color$$$$outer(), $name, _$ordinal)
            override def canEqual(that: Object): Boolean = 
              super[EnumValue].canEqual(that)
            override def productArity(): Int = super[EnumValue].productArity()
            override def productPrefix(): String = 
              super[EnumValue].productPrefix()
            override def productElement(n: Int): Object = 
              super[EnumValue].productElement(n)
            override def productElementName(n: Int): String = 
              super[EnumValue].productElementName(n)
            def fromProduct(p: Product): scala.deriving.Mirror.Singleton = 
              super[Singleton].fromProduct(p)
            def $ordinal(): Int = _$ordinal
            override def toString(): String = $name
            this.$outer.$values.register(this)
            private val $outer: Container.this.Color$
            final def Container$Color$_$$anon$$$outer(): Container.this.Color$
               = 
            $outer
            def fromProduct(p: Product): Object = this.fromProduct(p)
          }
          new 
            Container.this.Color with scala.runtime.EnumValue with 
              scala.deriving.Mirror.Singleton
             {...}
          (this):Container.this.Color
        }
      private val Red: Container.this.Color = this.$new(0, "Red")
      case def Red(): Container.this.Color = this.Red
      private val Green: Container.this.Color = this.$new(1, "Green")
      case def Green(): Container.this.Color = this.Green
      private val Blue: Container.this.Color = this.$new(2, "Blue")
      case def Blue(): Container.this.Color = this.Blue
      def ordinal(x$0: Container.this.Color): Int = x$0.ordinal()
      private val $outer: Container
      final def Container$Color$$$$outer(): Container = Container.Color.$outer
      def ordinal(x: Object): Int = 
        this.ordinal(x.asInstanceOf[Container.this.Color])
    }
  }
} of class class dotty.tools.dotc.ast.Trees$PackageDef # 2188
*** error while checking Container.scala after phase capturedVars ***
exception occurred while compiling Container.scala
java.lang.AssertionError: assertion failed: non member selection of getter Red in object Color from Container.this.Color.type in Color.this.$outer.Color.Red while compiling Container.scala
Exception in thread "main" java.lang.AssertionError: assertion failed: non member selection of getter Red in object Color from Container.this.Color.type in Color.this.$outer.Color.Red
	at dotty.DottyPredef$.assertFail(DottyPredef.scala:17)
	at dotty.tools.dotc.transform.FirstTransform.checkPostCondition(FirstTransform.scala:69)
	at dotty.tools.dotc.transform.TreeChecker.dotty$tools$dotc$transform$TreeChecker$Checker$$_$typedUnadapted$$anonfun$1(TreeChecker.scala:350)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:333)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:350)
	at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2553)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2554)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2557)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:317)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2671)
	at dotty.tools.dotc.typer.Typer.typedValDef(Typer.scala:1900)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2397)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2483)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:122)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:333)
	at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2553)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2554)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2557)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:317)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2579)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2627)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedStats(TreeChecker.scala:516)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2081)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedClassDef(TreeChecker.scala:448)
	at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$2(Typer.scala:2411)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2415)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2483)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:122)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:333)
	at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2553)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2554)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2557)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:317)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2579)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2627)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedStats(TreeChecker.scala:516)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2081)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedClassDef(TreeChecker.scala:448)
	at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$2(Typer.scala:2411)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2415)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2483)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:122)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:333)
	at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2553)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2554)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2557)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:317)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2579)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2627)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedStats(TreeChecker.scala:516)
	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2207)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2455)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2484)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:122)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:333)
	at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2553)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2554)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2557)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:317)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2671)
	at dotty.tools.dotc.transform.TreeChecker.check(TreeChecker.scala:151)
	at dotty.tools.dotc.transform.TreeChecker.run(TreeChecker.scala:120)
	at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:295)
	at scala.collection.immutable.List.map(List.scala:246)
	at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:296)
	at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:181)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
	at dotty.tools.dotc.Run.runPhases$5(Run.scala:191)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:199)
	at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:64)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:206)
	at dotty.tools.dotc.Run.compileSources(Run.scala:143)
	at dotty.tools.dotc.Run.compile(Run.scala:125)
	at dotty.tools.dotc.Driver.doCompile(Driver.scala:38)
	at dotty.tools.dotc.Driver.process(Driver.scala:195)
	at dotty.tools.dotc.Driver.process(Driver.scala:164)
	at dotty.tools.dotc.Driver.process(Driver.scala:176)
	at dotty.tools.dotc.Driver.main(Driver.scala:203)
	at dotty.tools.dotc.Main.main(Main.scala)
@bishabosha
Copy link
Member Author

bishabosha commented Aug 18, 2020

This should probably not be allowed as in JLS enums are always static classes

bishabosha added a commit to dotty-staging/dotty that referenced this issue Aug 28, 2020
bishabosha added a commit that referenced this issue Sep 2, 2020
fix #9579: prevent non static enums that extend jl.Enum
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
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.

2 participants