From 95d53235834ab650ded6768958697d2901fd4dd3 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sat, 28 Jul 2012 18:35:49 +0200 Subject: Closes SI-5882 I have added a restriction that value classes may not contain inner classes or objects. This makes sense as the "outer" field of any such classes or objects would be ephemeral, with surprising results. SIP-15 has been changed accordingly. --- test/files/neg/t5882.check | 15 +++++++++++++++ test/files/neg/t5882.scala | 5 +++++ 2 files changed, 20 insertions(+) create mode 100644 test/files/neg/t5882.check create mode 100644 test/files/neg/t5882.scala (limited to 'test') 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 +} -- cgit v1.2.3 From aad84ecba3eda180197bfbbb45a02393358c4c46 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 29 Jul 2012 16:23:20 +0200 Subject: SI-5799 Secondary constructors in value classes not allowed I changed the SIP and added a test. --- src/compiler/scala/tools/nsc/typechecker/Typers.scala | 8 ++++++-- test/files/neg/t5799.check | 4 ++++ test/files/neg/t5799.scala | 8 ++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 test/files/neg/t5799.check create mode 100644 test/files/neg/t5799.scala (limited to 'test') diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 393cbadc6a..130b03ebec 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1386,8 +1386,12 @@ trait Typers extends Modes with Adaptations with Tags { } } 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: 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) 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("") + } + -- cgit v1.2.3