Skip to content

Commit 0736cd4

Browse files
committed
WIP
1 parent e663ae5 commit 0736cd4

File tree

1 file changed

+31
-21
lines changed

1 file changed

+31
-21
lines changed

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

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,15 @@ class ErasurePreservation extends MiniPhase with InfoTransformer {
4040
if tr.isRef(defn.ShortClass) then TypeA.Short else
4141
if tr.isRef(defn.BooleanClass) then TypeA.Boolean else
4242
if tr.symbol.isTypeParam then
43-
val ind = tr.symbol.owner.paramSymss.head.indexWhere(tr.isRef(_))
44-
if ind != -1 then TypeA.M(ind)
45-
else TypeA.Ref
43+
val owner = tr.symbol.owner
44+
if owner.isClass then
45+
val ind = owner.typeParams.indexOf(tr.symbol)
46+
if ind != -1 then TypeA.K(ind) else ???
47+
else
48+
val ind = owner.paramSymss.headOption match
49+
case None => assert(false, i"Got unexpected type ${tp}")
50+
case Some(value) => value.indexWhere(tr.isRef(_))
51+
if ind != -1 then TypeA.M(ind) else ???
4652
else TypeA.Ref
4753
case _ => assert(false)
4854
}
@@ -56,26 +62,26 @@ class ErasurePreservation extends MiniPhase with InfoTransformer {
5662
val ind = owner.typeParams.indexOf(tr.symbol)
5763
if ind != -1 then TypeB.K(ind) else TypeB.None
5864
else
59-
println(i"$tp")
60-
???
61-
// val ind = owner.paramSymss.headOption match
62-
// case None => assert(false, i"Got unexpected type ${tp}")
63-
// case Some(value) => value.indexWhere(tr.isRef(_))
64-
// if ind != -1 then TypeB.M(ind) else TypeB.None
65+
val ind = owner.paramSymss.headOption match
66+
case None => assert(false, i"Got unexpected type ${tp}")
67+
case Some(value) => value.indexWhere(tr.isRef(_))
68+
if ind != -1 then TypeB.M(ind) else TypeB.None
6569
case _ => TypeB.None
6670
}
6771

6872
def toReturnTypeB(tp: Type)(using Context): TypeB = tp match
69-
case tr: TypeRef =>
70-
// println(tr.symbol.owner.paramSymss)
71-
if tr.symbol.isTypeParam then
72-
val ind = tr.symbol.owner.paramSymss.head.indexWhere(tr.isRef(_))
73-
if ind != -1 then TypeB.M(ind)
74-
else TypeB.None
75-
else TypeB.None
73+
case tr: TypeRef if tr.symbol.isTypeParam =>
74+
val owner = tr.symbol.owner
75+
if owner.isClass then
76+
val ind = owner.typeParams.indexOf(tr.symbol)
77+
if ind != -1 then TypeB.K(ind) else TypeB.None
78+
else
79+
val ind = owner.paramSymss.headOption match
80+
case None => assert(false, i"Got unexpected type ${tp}")
81+
case Some(value) => value.indexWhere(tr.isRef(_))
82+
if ind != -1 then TypeB.M(ind) else TypeB.None
7683
case _ => TypeB.None
7784

78-
7985
override def transformInfo(tp: Type, sym: Symbol)(using Context): Type = trace(i"transformInfo ${tp}, ${sym}") {
8086
tp match
8187
case pt: PolyType =>
@@ -127,14 +133,18 @@ enum TypeA:
127133
case Long
128134
case Short
129135
case Boolean
130-
case M(x: Int)
131-
case K(x: Int)
136+
case M(paramNum: Int)
137+
case K(
138+
// outer: Int,
139+
paramNum: Int)
132140
case Ref
133141

134142
enum TypeB:
135143
case None
136-
case M(x: Int)
137-
case K(x: Int)
144+
case M(paramNum: Int)
145+
case K(
146+
// outer: Int,
147+
paramNum: Int)
138148
// case class TypeB(tp: Type)
139149

140150
object InstructionTypeArguments extends Property.StickyKey[List[TypeA]]

0 commit comments

Comments
 (0)