summaryrefslogtreecommitdiff
path: root/test/files
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2012-09-20 18:22:39 +0200
committerGrzegorz Kossakowski <grzegorz.kossakowski@gmail.com>2012-10-03 13:44:16 +0200
commitef934492df93e0fd3d78e7a3d4f9cccaf765d4d5 (patch)
treee4cedab4789af1180a9be314d422d179f95e0c44 /test/files
parente9edc69684b3d55a0aef16325e358036c71f4c57 (diff)
downloadscala-ef934492df93e0fd3d78e7a3d4f9cccaf765d4d5.tar.gz
scala-ef934492df93e0fd3d78e7a3d4f9cccaf765d4d5.tar.bz2
scala-ef934492df93e0fd3d78e7a3d4f9cccaf765d4d5.zip
Revised restrictions for value classes and unversal traits
and brought compiler in line with them. One thing we can accept IMO are nested classes (nested objects are still a problem). In fact, it makes no sense to exclude nested classes from value classes but not from universal traits. A class nested in universal trait will becomes a class nested in a value class by inheritance. Note that the reflection library already contains a universal trait with a nested class (IndexedSeqLike), so we should accept them if we can.
Diffstat (limited to 'test/files')
-rw-r--r--test/files/neg/anytrait.check4
-rw-r--r--test/files/neg/t5799.check2
-rw-r--r--test/files/neg/t5882.check16
-rw-r--r--test/files/neg/t5882.scala5
-rw-r--r--test/files/neg/valueclasses.check4
-rw-r--r--test/files/run/t5882.scala14
6 files changed, 26 insertions, 19 deletions
diff --git a/test/files/neg/anytrait.check b/test/files/neg/anytrait.check
index 9dd970b58c..fabe74d379 100644
--- a/test/files/neg/anytrait.check
+++ b/test/files/neg/anytrait.check
@@ -1,7 +1,7 @@
-anytrait.scala:3: error: this statement is not allowed in universal trait extending from class Any: private[this] var x: Int = 1
+anytrait.scala:3: error: field definition is not allowed in universal trait extending from class Any
var x = 1
^
-anytrait.scala:5: error: this statement is not allowed in universal trait extending from class Any: T.this.x_=(T.this.x.+(1))
+anytrait.scala:5: error: this statement is not allowed in universal trait extending from class Any
{ x += 1 }
^
two errors found
diff --git a/test/files/neg/t5799.check b/test/files/neg/t5799.check
index 10e2658d56..3b43d06a94 100644
--- a/test/files/neg/t5799.check
+++ b/test/files/neg/t5799.check
@@ -1,4 +1,4 @@
-t5799.scala:2: error: value class may not have secondary constructors
+t5799.scala:2: error: secondary constructor is not allowed in value class
def this(s: String) = this(s.toDouble)
^
one error found
diff --git a/test/files/neg/t5882.check b/test/files/neg/t5882.check
index df01c7bc0a..b9ca5a1b2a 100644
--- a/test/files/neg/t5882.check
+++ b/test/files/neg/t5882.check
@@ -1,15 +1,7 @@
-t5882.scala:2: warning: case classes without a parameter list have been deprecated;
-use either case objects or case classes with `()' as parameter list.
- case class Scope
- ^
-t5882.scala:2: error: value class may not have nested class definitions
- case class Scope
+t5882.scala:4: error: nested object is not allowed in value class
+ case class Scope()
^
-t5882.scala:3: error: value class may not have nested class definitions
- class Foo
- ^
-t5882.scala:4: error: value class may not have nested module definitions
+t5882.scala:5: error: nested object is not allowed in value class
object Bar
^
-one warning found
-three errors found
+two errors found
diff --git a/test/files/neg/t5882.scala b/test/files/neg/t5882.scala
index 1233eb636f..3a55abdc9a 100644
--- a/test/files/neg/t5882.scala
+++ b/test/files/neg/t5882.scala
@@ -1,5 +1,6 @@
+// SIP-15 was changed to allow nested classes. See run/t5882.scala
+
class NodeOps(val n: Any) extends AnyVal {
- case class Scope
- class Foo
+ case class Scope()
object Bar
}
diff --git a/test/files/neg/valueclasses.check b/test/files/neg/valueclasses.check
index 4f042faded..3b82a8358c 100644
--- a/test/files/neg/valueclasses.check
+++ b/test/files/neg/valueclasses.check
@@ -25,13 +25,13 @@ class V5(private val x: Int) extends AnyVal // fail
valueclasses.scala:19: error: value class needs to have exactly one public val parameter
class V6(val x: Int, val y: String) extends AnyVal // fail
^
-valueclasses.scala:20: error: illegal parameter for value class
+valueclasses.scala:20: error: field definition is not allowed in value class
class V7(val x: Int, private[this] val y: String) extends AnyVal // fail
^
valueclasses.scala:21: error: value class needs to have exactly one public val parameter
class V8(var x: Int) extends AnyVal // fail
^
-valueclasses.scala:24: error: this statement is not allowed in value class: private[this] val y: Int = V9.this.x
+valueclasses.scala:24: error: field definition is not allowed in value class
val y = x // fail
^
valueclasses.scala:29: error: type parameter of value class may not be specialized
diff --git a/test/files/run/t5882.scala b/test/files/run/t5882.scala
new file mode 100644
index 0000000000..47996d3068
--- /dev/null
+++ b/test/files/run/t5882.scala
@@ -0,0 +1,14 @@
+// SIP-15 was revised to allow nested classes in value classes.
+// This test checks that their basic functionality.
+
+class NodeOps(val n: Any) extends AnyVal { self =>
+ class Foo() { def show = self.show(n) }
+ def show(x: Any) = x.toString
+}
+
+
+object Test extends App {
+
+ val n = new NodeOps("abc")
+ assert(new n.Foo().show == "abc")
+}