Skip to content

Commit 5c8188a

Browse files
committed
Fix generic signatures for static forwarders involving value classes
1 parent 43ca070 commit 5c8188a

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import dotty.tools.dotc.core.Types
2626
import dotty.tools.dotc.core.Types._
2727
import dotty.tools.dotc.core.TypeErasure
2828
import dotty.tools.dotc.transform.GenericSignatures
29+
import dotty.tools.dotc.transform.ElimErasedValueType
2930
import dotty.tools.io.AbstractFile
3031
import dotty.tools.dotc.report
3132

@@ -926,7 +927,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
926927
// (one that doesn't erase to the actual signature). See run/t3452b for a test case.
927928

928929
val memberTpe = atPhase(erasurePhase) { moduleClass.denot.thisType.memberInfo(sym) }
929-
val erasedMemberType = TypeErasure.transformInfo(sym, memberTpe)
930+
val erasedMemberType = ElimErasedValueType.elimEVT(TypeErasure.transformInfo(sym, memberTpe))
930931
if (erasedMemberType =:= sym.denot.info)
931932
getGenericSignatureHelper(sym, moduleClass, memberTpe).orNull
932933
else null

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ import NameKinds.SuperAccessorName
1313

1414
object ElimErasedValueType {
1515
val name: String = "elimErasedValueType"
16+
17+
def elimEVT(tp: Type)(using Context): Type = tp match {
18+
case ErasedValueType(_, underlying) =>
19+
elimEVT(underlying)
20+
case tp: MethodType =>
21+
val paramTypes = tp.paramInfos.mapConserve(elimEVT)
22+
val retType = elimEVT(tp.resultType)
23+
tp.derivedLambdaType(tp.paramNames, paramTypes, retType)
24+
case _ =>
25+
tp
26+
}
1627
}
1728

1829
/** This phase erases ErasedValueType to their underlying type.
@@ -25,6 +36,7 @@ object ElimErasedValueType {
2536
class ElimErasedValueType extends MiniPhase with InfoTransformer { thisPhase =>
2637

2738
import tpd._
39+
import ElimErasedValueType.elimEVT
2840

2941
override def phaseName: String = ElimErasedValueType.name
3042

@@ -48,17 +60,6 @@ class ElimErasedValueType extends MiniPhase with InfoTransformer { thisPhase =>
4860
elimEVT(tp)
4961
}
5062

51-
def elimEVT(tp: Type)(using Context): Type = tp match {
52-
case ErasedValueType(_, underlying) =>
53-
elimEVT(underlying)
54-
case tp: MethodType =>
55-
val paramTypes = tp.paramInfos.mapConserve(elimEVT)
56-
val retType = elimEVT(tp.resultType)
57-
tp.derivedLambdaType(tp.paramNames, paramTypes, retType)
58-
case _ =>
59-
tp
60-
}
61-
6263
def transformTypeOfTree(tree: Tree)(using Context): Tree =
6364
tree.withType(elimEVT(tree.tpe))
6465

tests/pos/i10347/A_1.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
trait L[+T] { def head: T }
2+
class K(val s: String) extends AnyVal
23
object A {
34
def foo: L[String] = ???
5+
def bar: L[K] = ???
6+
def baz(k: K): L[String] = ???
47
}

tests/pos/i10347/C_2.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
public class C_2 {
22
String hi = A.foo().head();
3+
String hy = A.bar().head();
4+
String hj = A.baz("").head();
35
}

0 commit comments

Comments
 (0)