diff --git a/compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala b/compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala index 6331913049c2..2ad58fea4cd1 100644 --- a/compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala +++ b/compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala @@ -397,6 +397,9 @@ trait BCodeHelpers extends BCodeIdiomatic { atPhase(erasurePhase) { val memberTpe = if (sym.is(Method)) sym.denot.info + else if sym.denot.validFor.phaseId > erasurePhase.id && sym.isField && sym.getter.exists then + // Memoization field of getter entered after erasure, see run/i17069 for an example + sym.getter.denot.info.resultType else owner.denot.thisType.memberInfo(sym) getGenericSignatureHelper(sym, owner, memberTpe).orNull } diff --git a/tests/generic-java-signatures/17069.scala b/tests/generic-java-signatures/17069.scala new file mode 100644 index 000000000000..279a8c88e2db --- /dev/null +++ b/tests/generic-java-signatures/17069.scala @@ -0,0 +1,10 @@ + +class Foo: + val generic: List[String] = ??? + +@main def Test = + val tpe = classOf[Foo].getDeclaredField("generic").getGenericType() + assert(tpe.getTypeName == "scala.collection.immutable.List") + + val tpe2 = classOf[Foo].getDeclaredMethod("generic").getGenericReturnType() + assert(tpe2.getTypeName == "scala.collection.immutable.List")