lms-sandbox
lms-sandbox copied to clipboard
Semantics of private conflicting vals in reified classes
This example returns "1abc" instead of 2, because the private fields x overwrite each other dynamically, instead of being resolved statically.
@gkossakowski suggests just renaming private fields to avoid conflict.
diff --git a/src/test/scala/scala/js/TestClasses.scala b/src/test/scala/scala/js/TestClasses.scala
index 60713c2..072cfed 100644
--- a/src/test/scala/scala/js/TestClasses.scala
+++ b/src/test/scala/scala/js/TestClasses.scala
@@ -60,6 +60,19 @@ trait ClassesProg { this: JS with JSClasses =>
}
implicit def proxyRepFooFun(x: Rep[FooFun]) = repClassProxy[FooFun](x, this)
+ class PrivateA {
+ private val x = unit(1)
+ def get() = x
+ }
+ implicit def proxyRepPrivateA(x: Rep[PrivateA]) = repClassProxy[PrivateA](x, this)
+
+ class PrivateB extends PrivateA {
+ private val x = unit("abc")
+ def get2() = x
+ def get3() = unit(2)
+ }
+ implicit def proxyRepPrivateB(x: Rep[PrivateB]) = repClassProxy[PrivateB](x, this)
+
def testClassProxy(foo: Rep[Foo]): Rep[Int] = {
foo.f()
}
@@ -147,6 +160,14 @@ trait ClassesProg { this: JS with JSClasses =>
val outProducer = fun { () => 1 }
(outProducer() + (fooFun.producer())()) // x+1
}
+
+ def testPrivateConflictingVals(x: Rep[Int]): Rep[Int] = {
+ val newA = registerClass[PrivateA](this)
+ val newB = registerClass[PrivateB](this)
+ val a = newA()
+ val b = newB()
+ a.get() + b.get()
+ }
}
class TestClasses extends FileDiffSuite {
@@ -292,6 +313,16 @@ class TestClasses extends FileDiffSuite {
assertFileEqualsCheck(prefix+"reified-class-fun-in-and-out")
}
+ def testPrivateConflictingVals = {
+ withOutFile(prefix+"reified-class-private-conflicting-vals") {
+ new ClassesProg with JSExp with JSClassesExp { self =>
+ val codegen = new JSGen with JSGenClasses { val IR: self.type = self }
+ codegen.emitSource(testPrivateConflictingVals _, "main", new PrintWriter(System.out))
+ }
+ }
+ assertFileEqualsCheck(prefix+"reified-class-private-conflicting-vals")
+ }
+
def testMixInClassesAndTraitsProxy = {
trait ClassesAndTraitsProxyProg { this: JS with JSClassProxyBase with JSProxyBase =>
}
@@ -307,4 +338,5 @@ class TestClasses extends FileDiffSuite {
val codegen = new JSGen with JSGenClasses with JSGenTraits { val IR: self.type = self }
}
}
+
}