aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/neg/singletons.scala11
-rw-r--r--tests/pos/singletons.scala56
-rw-r--r--tests/run/i763.scala12
-rw-r--r--tests/run/i764.scala14
-rw-r--r--tests/run/i768.scala10
5 files changed, 103 insertions, 0 deletions
diff --git a/tests/neg/singletons.scala b/tests/neg/singletons.scala
new file mode 100644
index 000000000..5dff13096
--- /dev/null
+++ b/tests/neg/singletons.scala
@@ -0,0 +1,11 @@
+object Test {
+ val a: 42 = 43 // error: different constant
+ val x = 42
+ val z: 42 = x // error: x is not final
+
+ val n: null = null // error: Null is not a legal singleton type
+
+ val sym: 'sym = 'sym // error: Symbol is a legal singleton type
+
+ val foo: s"abc" = "abc" // error: not a legal singleton type
+}
diff --git a/tests/pos/singletons.scala b/tests/pos/singletons.scala
new file mode 100644
index 000000000..4ce41a061
--- /dev/null
+++ b/tests/pos/singletons.scala
@@ -0,0 +1,56 @@
+
+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("x"); 2 } // side effects don't matter
+ val b: 2 = a
+
+ def f: 3 = 3
+ final val c = f
+
+ 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
+}
+/* To do: test that after erasure we have generated code like this:
+ *
+package <empty> {
+ final lazy module val Test: Test$ = new Test$()
+ final module class Test$() extends Object() { this: <notype> =>
+ <accessor> def x(): Int = 1
+ final <accessor> def y(): Int = 1
+ <accessor> def z(): Int = 1
+ final lazy module val O: Test.O$ = new Test.O$()
+ final module class O$() extends Object() { this: <notype> =>
+ final <accessor> def x(): Int = 42
+ }
+ <accessor> def fourtyTwo(): Int = 42
+ final <accessor> def a(): Int = {
+ println("x")
+ 2
+ }
+ <accessor> def b(): Int = 2
+ def f(): Int = 3
+ final <accessor> def c(): Int = Test.f()
+ <accessor> def dc(): Double = 3.0
+ final <accessor> def dc1(): Double = 3.0
+ <accessor> def fc(): Float = 3.0
+ final <accessor> def fc1(): Float = 3.0
+ <accessor> def t(): Boolean = true
+ <accessor> def str(): String = ""
+ final <accessor> def str2(): String = ""
+ }
+}
+*/
diff --git a/tests/run/i763.scala b/tests/run/i763.scala
new file mode 100644
index 000000000..e60b9cbc0
--- /dev/null
+++ b/tests/run/i763.scala
@@ -0,0 +1,12 @@
+abstract class A {
+ val s: Int
+ assert(s == 1)
+}
+
+class B(val s: Int) extends A
+
+object Test extends B(1) {
+ def main(args: Array[String]): Unit = {
+ s
+ }
+}
diff --git a/tests/run/i764.scala b/tests/run/i764.scala
new file mode 100644
index 000000000..921bdd23b
--- /dev/null
+++ b/tests/run/i764.scala
@@ -0,0 +1,14 @@
+abstract class A {
+ def foo: Int
+}
+
+trait B {
+ def foo = 2
+}
+
+object Test extends A with B {
+
+ def main(args: Array[String]): Unit = {
+ this.foo
+ }
+}
diff --git a/tests/run/i768.scala b/tests/run/i768.scala
new file mode 100644
index 000000000..0697b476b
--- /dev/null
+++ b/tests/run/i768.scala
@@ -0,0 +1,10 @@
+case class A(a: String*){
+ val s = a.toString
+}
+
+object Test {
+ def main(args: Array[String]) =
+ assert(A("a", "bc").s == "WrappedArray(a, bc)")
+}
+
+