From 6235c45150a4a701aa006c304ded58becdc9a3ad Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sat, 12 Sep 2015 15:28:47 +0200 Subject: Add test Should have been added on final vals commit. --- tests/run/singletons.check | 3 ++ tests/run/singletons.scala | 71 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 tests/run/singletons.check create mode 100644 tests/run/singletons.scala (limited to 'tests') diff --git a/tests/run/singletons.check b/tests/run/singletons.check new file mode 100644 index 000000000..96b14b69e --- /dev/null +++ b/tests/run/singletons.check @@ -0,0 +1,3 @@ +a +g +g diff --git a/tests/run/singletons.scala b/tests/run/singletons.scala new file mode 100644 index 000000000..0a1eda14f --- /dev/null +++ b/tests/run/singletons.scala @@ -0,0 +1,71 @@ + +object Test { + + val x: 1 = 1 + final val y = x + val z: 1 = y + + object O { final val x = 42 } + val fourtyTwo: 42 = O.x + + final val a = { println("a"); 2 } // side effect does not matter for type but needs to be preserved at runtime + val b: 2 = a + + def f: 3 = 3 + final val c = f + + final def g: 4 = { println("g"); 4 } // side effect does not matter for type but needs to be preserved at runtime + final val gv1: 4 = g + final val gv2: 4 = g + + val dc: 3.0 = 3.0 + final val dc1 = dc + val fc: 3.0f = 3.0f + final val fc1 = fc + + val t: true = true + + val str: "" = "" + final val str2 = str + + def main(args: Array[String]) = { + } +} +/* To do: test that after erasure we have generated code like this: + * +package { + final lazy module val Test: Test$ = new Test$() + final module class Test$() extends Object() { this: => + def x(): Int = 1 + final def y(): Int = 1 + def z(): Int = 1 + final lazy module val O: Test.O$ = new Test.O$() + final module class O$() extends Object() { this: => + final def x(): Int = 42 + } + def fourtyTwo(): Int = 42 + final def a(): Int = { + println("a") + 2 + } + def b(): Int = 2 + def f(): Int = 3 + final def c(): Int = Test.f() + final def g(): Int = { + println("g") + 4 + } + final def gv(): Int = Test.g() + def dc(): Double = 3.0 + final def dc1(): Double = 3.0 + def fc(): Float = 3.0 + final def fc1(): Float = 3.0 + def t(): Boolean = true + def str(): String = "" + final def str2(): String = "" + def main(args: String[]): Unit = { + () + } + } +} +*/ -- cgit v1.2.3