Skip to content

Commit c3a7f46

Browse files
committed
add an isCompanionMethod convenience method
1 parent 73f74cb commit c3a7f46

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,15 @@ object SymDenotations {
370370
final def isAnonymousModuleVal(implicit ctx: Context) =
371371
this.symbol.is(ModuleVal) && (initial.asSymDenotation.name startsWith nme.ANON_CLASS)
372372

373+
/** Is this a companion class method or companion object method?
374+
* These methods are generated by Symbols#synthesizeCompanionMethod
375+
* and used in SymDenotations#companionClass and
376+
* SymDenotations#companionModule .
377+
*/
378+
final def isCompanionMethod(implicit ctx: Context) =
379+
name.toTermName == nme.COMPANION_CLASS_METHOD ||
380+
name.toTermName == nme.COMPANION_MODULE_METHOD
381+
373382
/** Is symbol a primitive value class? */
374383
def isPrimitiveValueClass(implicit ctx: Context) = defn.ScalaValueClasses contains symbol
375384

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,14 @@ 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.
145+
* - For companion methods : the erasure of their type with semiEraseVCs = false.
146+
* The signature of these methods are used to keep a
147+
* link between companions and should not be semi-erased.
148148
* - For all other symbols : the semi-erasure of their types, with
149149
* isJava, isConstructor set according to symbol.
150150
*/
151151
def transformInfo(sym: Symbol, tp: Type)(implicit ctx: Context): Type = {
152-
val semiEraseVCs = sym.name ne nme.COMPANION_CLASS_METHOD
152+
val semiEraseVCs = !sym.isCompanionMethod
153153
val erase = erasureFn(sym is JavaDefined, semiEraseVCs, sym.isConstructor, wildcardOK = false)
154154

155155
def eraseParamBounds(tp: PolyType): Type =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ object ValueClasses {
2525
!d.isConstructor &&
2626
!d.is(SuperAccessor) &&
2727
!d.is(Macro) &&
28-
!(d.name eq nme.COMPANION_MODULE_METHOD)
28+
!d.isCompanionMethod
2929

3030
/** The member that of a derived value class that unboxes it. */
3131
def valueClassUnbox(d: ClassDenotation)(implicit ctx: Context): Symbol =

0 commit comments

Comments
 (0)