Skip to content

Commit cb8ed16

Browse files
committed
fix: use underlying of VCs to compute generic signature
1 parent 2f39bfa commit cb8ed16

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,9 @@ object GenericSignatures {
276276
else builder.append(defn.typeTag(sym.info))
277277
else if (sym.isDerivedValueClass) {
278278
if (unboxedVCs) {
279-
val erasedUnderlying = fullErasure(tp)
280-
jsig(erasedUnderlying, toplevel = toplevel, unboxedVCs = true)
279+
val underlying = ValueClasses
280+
.underlyingOfValueClass(sym.asClass, tp)
281+
jsig(underlying, toplevel = toplevel, unboxedVCs = true)
281282
} else classSig(sym, pre, args)
282283
}
283284
else if (defn.isSyntheticFunctionClass(sym)) {

compiler/src/dotty/tools/dotc/transform/ValueClasses.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,9 @@ object ValueClasses {
4444
/** The unboxed type that underlies a derived value class */
4545
def underlyingOfValueClass(sym: ClassSymbol)(using Context): Type =
4646
valueClassUnbox(sym).info.resultType
47+
48+
/** The unboxed type that underlies a derived value class as seen from as seen from tpe*/
49+
def underlyingOfValueClass(sym: ClassSymbol, tpe: Type)(using Context): Type =
50+
valueClassUnbox(sym).info.resultType.asSeenFrom(tpe, sym)
51+
4752
}

tests/run/i24276.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
public <A> scala.Option<Box<A>> Foo.bar(scala.Option<Box<A>>)
2+
public <A> A Foo.foo(A)
3+
public static <A> scala.Option<Box<A>> Foo.sbar(scala.Option<Box<A>>)
4+
public static <A> A Foo.sfoo(A)

tests/run/i24276.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Box[A](value: A) extends AnyVal
2+
3+
class Foo:
4+
def foo[A](a: A): Box[A] = Box(a)
5+
def bar[A](opt: Option[Box[A]]): Option[Box[A]] = opt
6+
7+
object Foo:
8+
def sfoo[A](a: A): Box[A] = Box(a)
9+
def sbar[A](opt: Option[Box[A]]): Option[Box[A]] = opt
10+
11+
@main def Test =
12+
for mtd <- classOf[Foo].getDeclaredMethods.sortBy(_.getName) do
13+
println(mtd.toGenericString)

0 commit comments

Comments
 (0)