aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Petrashko <dark@d-d.me>2015-05-04 19:00:12 +0200
committerDmitry Petrashko <dark@d-d.me>2015-05-04 19:00:12 +0200
commit61ddff45164aa23a06c255596c1c2d53cdf0e76c (patch)
tree07228e018da1a63200a9c7875ee0f728c4b348a9
parent3b3a51f793c8fb65f94c121c1dcc2ce3aa0afb39 (diff)
parente8f32243cf25656f1ffc751d48bb792f73219e95 (diff)
downloaddotty-61ddff45164aa23a06c255596c1c2d53cdf0e76c.tar.gz
dotty-61ddff45164aa23a06c255596c1c2d53cdf0e76c.tar.bz2
dotty-61ddff45164aa23a06c255596c1c2d53cdf0e76c.zip
Merge pull request #532 from smarter/fix/vc-java-compat
Fix compatibility of Java with value classes
-rw-r--r--src/dotty/tools/dotc/core/SymDenotations.scala9
-rw-r--r--src/dotty/tools/dotc/core/TypeErasure.scala13
-rw-r--r--src/dotty/tools/dotc/transform/ValueClasses.scala2
-rw-r--r--tests/pos/valueclasses/t9298/JUse.java7
-rw-r--r--tests/pos/valueclasses/t9298/Meter.scala3
-rw-r--r--tests/pos/valueclasses/t9298/Use.scala9
6 files changed, 37 insertions, 6 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..71146bd4e 100644
--- a/src/dotty/tools/dotc/core/TypeErasure.scala
+++ b/src/dotty/tools/dotc/core/TypeErasure.scala
@@ -142,15 +142,18 @@ 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 Java-defined symbols: : the erasure of their type with isJava = true,
+ * semiEraseVCs = false. Semi-erasure never happens in Java.
* - 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 erase = erasureFn(sym is JavaDefined, semiEraseVCs, sym.isConstructor, wildcardOK = false)
+ val isJava = sym is JavaDefined
+ val semiEraseVCs = !isJava && !sym.isCompanionMethod
+ val erase = erasureFn(isJava, semiEraseVCs, sym.isConstructor, wildcardOK = false)
def eraseParamBounds(tp: PolyType): Type =
tp.derivedPolyType(
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 =
diff --git a/tests/pos/valueclasses/t9298/JUse.java b/tests/pos/valueclasses/t9298/JUse.java
new file mode 100644
index 000000000..a872c895a
--- /dev/null
+++ b/tests/pos/valueclasses/t9298/JUse.java
@@ -0,0 +1,7 @@
+package t9298;
+
+class JUse {
+ public static Meter jm() {
+ return new Meter(2);
+ }
+}
diff --git a/tests/pos/valueclasses/t9298/Meter.scala b/tests/pos/valueclasses/t9298/Meter.scala
new file mode 100644
index 000000000..290b28509
--- /dev/null
+++ b/tests/pos/valueclasses/t9298/Meter.scala
@@ -0,0 +1,3 @@
+package t9298
+
+class Meter(val x: Int) extends AnyVal
diff --git a/tests/pos/valueclasses/t9298/Use.scala b/tests/pos/valueclasses/t9298/Use.scala
new file mode 100644
index 000000000..41f1fb035
--- /dev/null
+++ b/tests/pos/valueclasses/t9298/Use.scala
@@ -0,0 +1,9 @@
+// TODO: this should be a run test once we have run tests
+
+package t9298
+
+object Use {
+ def main(args: Array[String]): Unit = {
+ val x: Meter = JUse.jm
+ }
+}