diff options
author | Guillaume Martres <smarter@ubuntu.com> | 2015-05-01 21:46:06 +0200 |
---|---|---|
committer | Guillaume Martres <smarter@ubuntu.com> | 2015-05-04 15:50:09 +0200 |
commit | c3a7f461cd8e9a2f6c69ff85745da7892d0aa124 (patch) | |
tree | 3ed19638b00b3142534deae6e8d6f135c28c3fed | |
parent | 73f74cb2d40bc6a8ff3a0944a1706de91fe7f535 (diff) | |
download | dotty-c3a7f461cd8e9a2f6c69ff85745da7892d0aa124.tar.gz dotty-c3a7f461cd8e9a2f6c69ff85745da7892d0aa124.tar.bz2 dotty-c3a7f461cd8e9a2f6c69ff85745da7892d0aa124.zip |
add an isCompanionMethod convenience method
-rw-r--r-- | src/dotty/tools/dotc/core/SymDenotations.scala | 9 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/TypeErasure.scala | 8 | ||||
-rw-r--r-- | src/dotty/tools/dotc/transform/ValueClasses.scala | 2 |
3 files changed, 14 insertions, 5 deletions
diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index 30504bc8d..275fb8257 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -370,6 +370,15 @@ object SymDenotations { final def isAnonymousModuleVal(implicit ctx: Context) = this.symbol.is(ModuleVal) && (initial.asSymDenotation.name startsWith nme.ANON_CLASS) + /** Is this a companion class method or companion object method? + * These methods are generated by Symbols#synthesizeCompanionMethod + * and used in SymDenotations#companionClass and + * SymDenotations#companionModule . + */ + final def isCompanionMethod(implicit ctx: Context) = + name.toTermName == nme.COMPANION_CLASS_METHOD || + name.toTermName == nme.COMPANION_MODULE_METHOD + /** Is symbol a primitive value class? */ def isPrimitiveValueClass(implicit ctx: Context) = defn.ScalaValueClasses contains symbol diff --git a/src/dotty/tools/dotc/core/TypeErasure.scala b/src/dotty/tools/dotc/core/TypeErasure.scala index e695e6721..9d5436d9f 100644 --- a/src/dotty/tools/dotc/core/TypeErasure.scala +++ b/src/dotty/tools/dotc/core/TypeErasure.scala @@ -142,14 +142,14 @@ object TypeErasure { * - For $asInstanceOf : [T]T * - For $isInstanceOf : [T]Boolean * - For all abstract types : = ? - * - For COMPANION_CLASS_METHOD : the erasure of their type with semiEraseVCs = false, - * this is needed to keep [[SymDenotation#companionClass]] - * working after erasure for value classes. + * - For companion methods : the erasure of their type with semiEraseVCs = false. + * The signature of these methods are used to keep a + * link between companions and should not be semi-erased. * - For all other symbols : the semi-erasure of their types, with * isJava, isConstructor set according to symbol. */ def transformInfo(sym: Symbol, tp: Type)(implicit ctx: Context): Type = { - val semiEraseVCs = sym.name ne nme.COMPANION_CLASS_METHOD + val semiEraseVCs = !sym.isCompanionMethod val erase = erasureFn(sym is JavaDefined, semiEraseVCs, sym.isConstructor, wildcardOK = false) def eraseParamBounds(tp: PolyType): Type = diff --git a/src/dotty/tools/dotc/transform/ValueClasses.scala b/src/dotty/tools/dotc/transform/ValueClasses.scala index 8969b9321..f17a0e757 100644 --- a/src/dotty/tools/dotc/transform/ValueClasses.scala +++ b/src/dotty/tools/dotc/transform/ValueClasses.scala @@ -25,7 +25,7 @@ object ValueClasses { !d.isConstructor && !d.is(SuperAccessor) && !d.is(Macro) && - !(d.name eq nme.COMPANION_MODULE_METHOD) + !d.isCompanionMethod /** The member that of a derived value class that unboxes it. */ def valueClassUnbox(d: ClassDenotation)(implicit ctx: Context): Symbol = |