diff --git a/compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala b/compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala index 96ae4e8a00af..6516d32b6518 100644 --- a/compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala +++ b/compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala @@ -390,7 +390,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder { def genLoadQualUnlessElidable(): Unit = { if (!qualSafeToElide) { genLoadQualifier(tree) } } // receiverClass is used in the bytecode to access the field. using sym.owner may lead to IllegalAccessError - def receiverClass = qualifier.tpe.typeSymbol + def receiverClass = qualifier.tpe.widenTermRefExpr.finalResultType.typeSymbol if (sym.is(Module)) { genLoadQualUnlessElidable() genLoadModule(tree) diff --git a/tests/pos/i13490.scala b/tests/pos/i13490.scala new file mode 100644 index 000000000000..c8f3213e0649 --- /dev/null +++ b/tests/pos/i13490.scala @@ -0,0 +1,17 @@ +object MyApi { + enum MyEnum(a: Int) { + case A extends MyEnum(1) + } + case class Foo(a: MyEnum) +} + +object Test { + export MyApi.* + import MyEnum.* + Foo(MyEnum.A) match { + case Foo(a) => + a match { + case A => + } + } +} diff --git a/tests/run/i13490.min.scala b/tests/run/i13490.min.scala new file mode 100644 index 000000000000..4f9c19764a5d --- /dev/null +++ b/tests/run/i13490.min.scala @@ -0,0 +1,13 @@ +object MyTypes: + enum MyEnum: + case Foo + case Bar + +object MyApi: + export MyTypes.* + +object MyUse: + import MyApi.MyEnum.Foo + def foo = Foo + +@main def Test = assert(MyUse.foo.toString == "Foo")