Skip to content

Commit

Permalink
Fix getter memoized field signature
Browse files Browse the repository at this point in the history
Co-authored-by: Carlo Sana <[email protected]>
Co-authored-by: Matt Bovel <[email protected]>
  • Loading branch information
2 people authored and EugeneFlesselle committed Dec 8, 2023
1 parent a3854cb commit dad90f4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 10 additions & 0 deletions tests/generic-java-signatures/17069.scala
Original file line number Diff line number Diff line change
@@ -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<java.lang.String>")

val tpe2 = classOf[Foo].getDeclaredMethod("generic").getGenericReturnType()
assert(tpe2.getTypeName == "scala.collection.immutable.List<java.lang.String>")

0 comments on commit dad90f4

Please sign in to comment.