diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 17 | ||||
-rw-r--r-- | test/files/neg/t6359.check | 7 | ||||
-rw-r--r-- | test/files/neg/t6359.scala | 8 |
3 files changed, 24 insertions, 8 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index d90141b732..e96f2f75c7 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1405,14 +1405,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 _ => + + def valueClassMayNotHave(at: Tree, what: String) = unit.error(at.pos, s"value class may not have $what") + body.foreach { + case dd: DefDef if dd.symbol.isAuxiliaryConstructor => valueClassMayNotHave(dd, "secondary constructors") + case t => t.foreach { + case md: ModuleDef => valueClassMayNotHave(md, "nested module definitions") + case cd: ClassDef => valueClassMayNotHave(cd, "nested class definitions") + case _ => + } } for (tparam <- clazz.typeParams) if (tparam hasAnnotation definitions.SpecializedClass) diff --git a/test/files/neg/t6359.check b/test/files/neg/t6359.check new file mode 100644 index 0000000000..2aa1ac5035 --- /dev/null +++ b/test/files/neg/t6359.check @@ -0,0 +1,7 @@ +t6359.scala:3: error: value class may not have nested module definitions + object X + ^ +t6359.scala:4: error: value class may not have nested class definitions + class Y + ^ +two errors found diff --git a/test/files/neg/t6359.scala b/test/files/neg/t6359.scala new file mode 100644 index 0000000000..96550fd906 --- /dev/null +++ b/test/files/neg/t6359.scala @@ -0,0 +1,8 @@ +class M(val t: Int) extends AnyVal { + def lazyString = { + object X + class Y + + () => {X; new Y} + } +} |