diff options
author | Martin Odersky <odersky@gmail.com> | 2012-07-28 18:35:49 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2012-07-28 18:35:59 +0200 |
commit | 95d53235834ab650ded6768958697d2901fd4dd3 (patch) | |
tree | e712179c1b975aa880746ef82d581353a5480931 | |
parent | 1f95d356ee69a442f98aedc024a1aa7e4672d20a (diff) | |
download | scala-95d53235834ab650ded6768958697d2901fd4dd3.tar.gz scala-95d53235834ab650ded6768958697d2901fd4dd3.tar.bz2 scala-95d53235834ab650ded6768958697d2901fd4dd3.zip |
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.
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 7 | ||||
-rw-r--r-- | test/files/neg/t5882.check | 15 | ||||
-rw-r--r-- | test/files/neg/t5882.scala | 5 |
3 files changed, 26 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 269ab9611a..393cbadc6a 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1385,6 +1385,11 @@ 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 _ => + } for (tparam <- clazz.typeParams) if (tparam hasAnnotation definitions.SpecializedClass) unit.error(tparam.pos, "type parameter of value class may not be specialized") @@ -4531,7 +4536,7 @@ trait Typers extends Modes with Adaptations with Tags { assert(errorContainer == null, "Cannot set ambiguous error twice for identifier") errorContainer = tree } - + val fingerPrint: Long = name.fingerPrint var defSym: Symbol = tree.symbol // the directly found symbol 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 +} |