File tree Expand file tree Collapse file tree 5 files changed +41
-0
lines changed
src/compiler/scala/tools/nsc/typechecker Expand file tree Collapse file tree 5 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -1401,6 +1401,15 @@ trait Typers extends Modes with Adaptations with Tags {
14011401 unit.error(clazz.pos, " value class needs to have exactly one public val parameter" )
14021402 }
14031403 }
1404+ body foreach {
1405+ case md : ModuleDef =>
1406+ unit.error(md.pos, " value class may not have nested module definitions" )
1407+ case cd : ClassDef =>
1408+ unit.error(cd.pos, " value class may not have nested class definitions" )
1409+ case md : DefDef if md.symbol.isConstructor && ! md.symbol.isPrimaryConstructor =>
1410+ unit.error(md.pos, " value class may not have secondary constructors" )
1411+ case _ =>
1412+ }
14041413 for (tparam <- clazz.typeParams)
14051414 if (tparam hasAnnotation definitions.SpecializedClass )
14061415 unit.error(tparam.pos, " type parameter of value class may not be specialized" )
Original file line number Diff line number Diff line change 1+ t5799.scala:2: error: value class may not have secondary constructors
2+ def this(s: String) = this(s.toDouble)
3+ ^
4+ one error found
Original file line number Diff line number Diff line change 1+ class Foo (val bar : Double ) extends AnyVal {
2+ def this (s : String ) = this (s.toDouble)
3+ }
4+ object Test {
5+ def main (args : Array [String ]): Unit =
6+ new Foo (" " )
7+ }
8+
Original file line number Diff line number Diff line change 1+ t5882.scala:2: warning: case classes without a parameter list have been deprecated;
2+ use either case objects or case classes with `()' as parameter list.
3+ case class Scope
4+ ^
5+ t5882.scala:2: error: value class may not have nested class definitions
6+ case class Scope
7+ ^
8+ t5882.scala:3: error: value class may not have nested class definitions
9+ class Foo
10+ ^
11+ t5882.scala:4: error: value class may not have nested module definitions
12+ object Bar
13+ ^
14+ one warning found
15+ three errors found
Original file line number Diff line number Diff line change 1+ class NodeOps (val n : Any ) extends AnyVal {
2+ case class Scope
3+ class Foo
4+ object Bar
5+ }
You can’t perform that action at this time.
0 commit comments