Skip to content

Commit 6235c45

Browse files
committed
Add test
Should have been added on final vals commit.
1 parent 5386c88 commit 6235c45

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

tests/run/singletons.check

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
a
2+
g
3+
g

tests/run/singletons.scala

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
2+
object Test {
3+
4+
val x: 1 = 1
5+
final val y = x
6+
val z: 1 = y
7+
8+
object O { final val x = 42 }
9+
val fourtyTwo: 42 = O.x
10+
11+
final val a = { println("a"); 2 } // side effect does not matter for type but needs to be preserved at runtime
12+
val b: 2 = a
13+
14+
def f: 3 = 3
15+
final val c = f
16+
17+
final def g: 4 = { println("g"); 4 } // side effect does not matter for type but needs to be preserved at runtime
18+
final val gv1: 4 = g
19+
final val gv2: 4 = g
20+
21+
val dc: 3.0 = 3.0
22+
final val dc1 = dc
23+
val fc: 3.0f = 3.0f
24+
final val fc1 = fc
25+
26+
val t: true = true
27+
28+
val str: "" = ""
29+
final val str2 = str
30+
31+
def main(args: Array[String]) = {
32+
}
33+
}
34+
/* To do: test that after erasure we have generated code like this:
35+
*
36+
package <empty> {
37+
final lazy module val Test: Test$ = new Test$()
38+
final module class Test$() extends Object() { this: <notype> =>
39+
<accessor> def x(): Int = 1
40+
final <accessor> def y(): Int = 1
41+
<accessor> def z(): Int = 1
42+
final lazy module val O: Test.O$ = new Test.O$()
43+
final module class O$() extends Object() { this: <notype> =>
44+
final <accessor> def x(): Int = 42
45+
}
46+
<accessor> def fourtyTwo(): Int = 42
47+
final <accessor> def a(): Int = {
48+
println("a")
49+
2
50+
}
51+
<accessor> def b(): Int = 2
52+
def f(): Int = 3
53+
final <accessor> def c(): Int = Test.f()
54+
final def g(): Int = {
55+
println("g")
56+
4
57+
}
58+
final <accessor> def gv(): Int = Test.g()
59+
<accessor> def dc(): Double = 3.0
60+
final <accessor> def dc1(): Double = 3.0
61+
<accessor> def fc(): Float = 3.0
62+
final <accessor> def fc1(): Float = 3.0
63+
<accessor> def t(): Boolean = true
64+
<accessor> def str(): String = ""
65+
final <accessor> def str2(): String = ""
66+
def main(args: String[]): Unit = {
67+
()
68+
}
69+
}
70+
}
71+
*/

0 commit comments

Comments
 (0)