Skip to content

Commit b0556ee

Browse files
dwijnandSethTisue
authored andcommitted
Fix backend assertion when using an exported enum
An exported enum is a <static> final method of the enum object. When selecting an inner enum case from it, that method will be the prefix. The method doesn't have a type symbol, we have to widen to method type and reach for its result type before we can get a handle on the type symbol to key off of. I wonder whether this widening and going to the result type is something that should happen during Erasure's denotation transformation though... Co-authored-by: Seth Tisue <[email protected]>
1 parent ddac928 commit b0556ee

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
390390
def genLoadQualUnlessElidable(): Unit = { if (!qualSafeToElide) { genLoadQualifier(tree) } }
391391

392392
// receiverClass is used in the bytecode to access the field. using sym.owner may lead to IllegalAccessError
393-
def receiverClass = qualifier.tpe.typeSymbol
393+
def receiverClass = qualifier.tpe.widenTermRefExpr.finalResultType.typeSymbol
394394
if (sym.is(Module)) {
395395
genLoadQualUnlessElidable()
396396
genLoadModule(tree)

tests/pos/i13490.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
object MyApi {
2+
enum MyEnum(a: Int) {
3+
case A extends MyEnum(1)
4+
}
5+
case class Foo(a: MyEnum)
6+
}
7+
8+
object Test {
9+
export MyApi.*
10+
import MyEnum.*
11+
Foo(MyEnum.A) match {
12+
case Foo(a) =>
13+
a match {
14+
case A =>
15+
}
16+
}
17+
}

tests/run/i13490.min.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
object MyTypes:
2+
enum MyEnum:
3+
case Foo
4+
case Bar
5+
6+
object MyApi:
7+
export MyTypes.*
8+
9+
object MyUse:
10+
import MyApi.MyEnum.Foo
11+
def foo = Foo
12+
13+
@main def Test = assert(MyUse.foo.toString == "Foo")

0 commit comments

Comments
 (0)