summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Suereth <Joshua.Suereth@gmail.com>2012-07-30 17:32:08 -0700
committerJosh Suereth <Joshua.Suereth@gmail.com>2012-07-30 17:32:08 -0700
commitf429c64601ee1c9036eafe9e7ace9b941d24ed07 (patch)
treec6083f57c00b96b94dc110409ad5c67c6981d61e
parente0b3e9e755d42da7d26977a6c6908a4239e49f3a (diff)
parentaad84ecba3eda180197bfbbb45a02393358c4c46 (diff)
downloadscala-f429c64601ee1c9036eafe9e7ace9b941d24ed07.tar.gz
scala-f429c64601ee1c9036eafe9e7ace9b941d24ed07.tar.bz2
scala-f429c64601ee1c9036eafe9e7ace9b941d24ed07.zip
Merge pull request #1011 from odersky/ticket/5882
Closes SI-5882
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala9
-rw-r--r--test/files/neg/t5799.check4
-rw-r--r--test/files/neg/t5799.scala8
-rw-r--r--test/files/neg/t5882.check15
-rw-r--r--test/files/neg/t5882.scala5
5 files changed, 41 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 5c25cd008b..e57cae00e0 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -1401,6 +1401,15 @@ trait Typers extends Modes with Adaptations with Tags {
unit.error(clazz.pos, "value class needs to have exactly one public val parameter")
}
}
+ body foreach {
+ case md: ModuleDef =>
+ unit.error(md.pos, "value class may not have nested module definitions")
+ case cd: ClassDef =>
+ unit.error(cd.pos, "value class may not have nested class definitions")
+ case md: DefDef if md.symbol.isConstructor && !md.symbol.isPrimaryConstructor =>
+ unit.error(md.pos, "value class may not have secondary constructors")
+ case _ =>
+ }
for (tparam <- clazz.typeParams)
if (tparam hasAnnotation definitions.SpecializedClass)
unit.error(tparam.pos, "type parameter of value class may not be specialized")
diff --git a/test/files/neg/t5799.check b/test/files/neg/t5799.check
new file mode 100644
index 0000000000..10e2658d56
--- /dev/null
+++ b/test/files/neg/t5799.check
@@ -0,0 +1,4 @@
+t5799.scala:2: error: value class may not have secondary constructors
+ def this(s: String) = this(s.toDouble)
+ ^
+one error found
diff --git a/test/files/neg/t5799.scala b/test/files/neg/t5799.scala
new file mode 100644
index 0000000000..9bd6ab7dd1
--- /dev/null
+++ b/test/files/neg/t5799.scala
@@ -0,0 +1,8 @@
+class Foo(val bar: Double) extends AnyVal {
+ def this(s: String) = this(s.toDouble)
+}
+object Test {
+ def main(args: Array[String]): Unit =
+ new Foo("")
+ }
+
diff --git a/test/files/neg/t5882.check b/test/files/neg/t5882.check
new file mode 100644
index 0000000000..df01c7bc0a
--- /dev/null
+++ b/test/files/neg/t5882.check
@@ -0,0 +1,15 @@
+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:3: error: value class may not have nested class definitions
+ class Foo
+ ^
+t5882.scala:4: error: value class may not have nested module definitions
+ object Bar
+ ^
+one warning found
+three errors found
diff --git a/test/files/neg/t5882.scala b/test/files/neg/t5882.scala
new file mode 100644
index 0000000000..1233eb636f
--- /dev/null
+++ b/test/files/neg/t5882.scala
@@ -0,0 +1,5 @@
+class NodeOps(val n: Any) extends AnyVal {
+ case class Scope
+ class Foo
+ object Bar
+}