Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,9 @@ object GenericSignatures {
else builder.append(defn.typeTag(sym.info))
else if (sym.isDerivedValueClass) {
if (unboxedVCs) {
val erasedUnderlying = fullErasure(tp)
jsig(erasedUnderlying, toplevel = toplevel, unboxedVCs = true)
val underlying = ValueClasses
.underlyingOfValueClass(sym.asClass, tp)
jsig(underlying, toplevel = toplevel, unboxedVCs = true)
} else classSig(sym, pre, args)
}
else if (defn.isSyntheticFunctionClass(sym)) {
Expand Down
5 changes: 5 additions & 0 deletions compiler/src/dotty/tools/dotc/transform/ValueClasses.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ object ValueClasses {
/** The unboxed type that underlies a derived value class */
def underlyingOfValueClass(sym: ClassSymbol)(using Context): Type =
valueClassUnbox(sym).info.resultType

/** The unboxed type that underlies a derived value class as seen from as seen from tpe*/
def underlyingOfValueClass(sym: ClassSymbol, tpe: Type)(using Context): Type =
valueClassUnbox(sym).info.resultType.asSeenFrom(tpe, sym)

}
12 changes: 12 additions & 0 deletions tests/run/i24276.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
public <A> scala.Option<Box<A>> Foo.bar1(scala.Option<Box<A>>)
public <A> scala.Option<IBox> Foo.bar2(scala.Option<IBox>)
public <A> scala.Option<SBox> Foo.bar3(scala.Option<SBox>)
public <A> A Foo.foo1(A)
public int Foo.foo2(int)
public java.lang.String Foo.foo3(java.lang.String)
public static <A> scala.Option<Box<A>> Foo.sbar1(scala.Option<Box<A>>)
public static <A> scala.Option<IBox> Foo.sbar2(scala.Option<IBox>)
public static <A> scala.Option<SBox> Foo.sbar3(scala.Option<SBox>)
public static <A> A Foo.sfoo1(A)
public static int Foo.sfoo2(int)
public static java.lang.String Foo.sfoo3(java.lang.String)
25 changes: 25 additions & 0 deletions tests/run/i24276.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// scalajs: --skip

class Box[A](value: A) extends AnyVal
class IBox(value: Int) extends AnyVal
class SBox(value: String) extends AnyVal

class Foo:
def foo1[A](a: A): Box[A] = Box(a)
def foo2(a: IBox): IBox = a
def foo3(a: SBox): SBox = a
def bar1[A](opt: Option[Box[A]]): Option[Box[A]] = opt
def bar2[A](opt: Option[IBox]): Option[IBox] = opt
def bar3[A](opt: Option[SBox]): Option[SBox] = opt

object Foo:
def sfoo1[A](a: A): Box[A] = Box(a)
def sfoo2(a: IBox): IBox = a
def sfoo3(a: SBox): SBox = a
def sbar1[A](opt: Option[Box[A]]): Option[Box[A]] = opt
def sbar2[A](opt: Option[IBox]): Option[IBox] = opt
def sbar3[A](opt: Option[SBox]): Option[SBox] = opt

@main def Test =
for mtd <- classOf[Foo].getDeclaredMethods.sortBy(_.getName) do
println(mtd.toGenericString)
2 changes: 1 addition & 1 deletion tests/run/i8001/B_2.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static void test() {

a.arr1(intArr);
a.arr2(stringArr);
a.arr3(intArr);
a.arr3(intArr2);
a.arr4(stringArr2);

a.arrRef1(integerArr);
Expand Down
Loading