Skip to content

Commit f429c64

Browse files
committed
Merge pull request scala#1011 from odersky/ticket/5882
Closes SI-5882
2 parents e0b3e9e + aad84ec commit f429c64

File tree

5 files changed

+41
-0
lines changed

5 files changed

+41
-0
lines changed

src/compiler/scala/tools/nsc/typechecker/Typers.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff 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")

test/files/neg/t5799.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
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

test/files/neg/t5799.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+

test/files/neg/t5882.check

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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

test/files/neg/t5882.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class NodeOps(val n: Any) extends AnyVal {
2+
case class Scope
3+
class Foo
4+
object Bar
5+
}

0 commit comments

Comments
 (0)