Skip to content

Commit 449055d

Browse files
smarterDarkDimius
authored andcommitted
Fix companionClass not working after Erasure for value classes
For a module class V$, the synthesized companion class method looks like: val companion$class: V If V is a value class, after erasure it will look like: val companion$class: ErasedValueType(V, ...) This will break SymDenotation#companionClass which relies on the type of companion$class. The solution is to not semi-erase the type of companion$class.
1 parent e5b02a8 commit 449055d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/dotty/tools/dotc/core/TypeErasure.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,15 @@ object TypeErasure {
142142
* - For $asInstanceOf : [T]T
143143
* - For $isInstanceOf : [T]Boolean
144144
* - For all abstract types : = ?
145+
* - For COMPANION_CLASS_METHOD : the erasure of their type with semiEraseVCs = false,
146+
* this is needed to keep [[SymDenotation#companionClass]]
147+
* working after erasure for value classes.
145148
* - For all other symbols : the semi-erasure of their types, with
146149
* isJava, isConstructor set according to symbol.
147150
*/
148151
def transformInfo(sym: Symbol, tp: Type)(implicit ctx: Context): Type = {
149-
val erase = erasureFn(sym is JavaDefined, semiEraseVCs = true, sym.isConstructor, wildcardOK = false)
152+
val semiEraseVCs = sym.name ne nme.COMPANION_CLASS_METHOD
153+
val erase = erasureFn(sym is JavaDefined, semiEraseVCs, sym.isConstructor, wildcardOK = false)
150154

151155
def eraseParamBounds(tp: PolyType): Type =
152156
tp.derivedPolyType(

0 commit comments

Comments
 (0)