diff options
-rw-r--r-- | compiler/src/dotty/tools/dotc/typer/Checking.scala | 2 | ||||
-rw-r--r-- | tests/neg/valueclasses-impl-restrictions.scala | 19 | ||||
-rw-r--r-- | tests/untried/neg/valueclasses-impl-restrictions.scala | 29 |
3 files changed, 21 insertions, 29 deletions
diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 321c275d7..ca62ed0a9 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -415,6 +415,8 @@ object Checking { /** Verify classes extending AnyVal meet the requirements */ def checkDerivedValueClass(clazz: Symbol, stats: List[Tree])(implicit ctx: Context) = { def checkValueClassMember(stat: Tree) = stat match { + case _: TypeDef if stat.symbol.isClass => + ctx.error(s"value class may not define an inner class", stat.pos) case _: ValDef if !stat.symbol.is(ParamAccessor) => ctx.error(s"value class may not define non-parameter field", stat.pos) case d: DefDef if d.symbol.isConstructor => diff --git a/tests/neg/valueclasses-impl-restrictions.scala b/tests/neg/valueclasses-impl-restrictions.scala new file mode 100644 index 000000000..9f33b7e7c --- /dev/null +++ b/tests/neg/valueclasses-impl-restrictions.scala @@ -0,0 +1,19 @@ +class X1(val s: String) extends AnyVal { + trait I2 { // error: value class may not define an inner class or trait + val q: String + def z = s + q + } +} + +class X2(val s: String) extends AnyVal { + private[this] class I2(val q: String) // error: value class may not define an inner class or trait + + def y(i: Int) = { + val i2 = new I2(i.toString) + i2.q + s + } +} + +class X3(val s: String) extends AnyVal { + object I3 // error: value class may not define non-parameter field +} diff --git a/tests/untried/neg/valueclasses-impl-restrictions.scala b/tests/untried/neg/valueclasses-impl-restrictions.scala deleted file mode 100644 index f0577a94a..000000000 --- a/tests/untried/neg/valueclasses-impl-restrictions.scala +++ /dev/null @@ -1,29 +0,0 @@ -class M(val t: Int) extends AnyVal { - def lazyString = { - object X - () => X - } -} - -class X1(val s: String) extends AnyVal { - trait I2 { - val q: String - def z = s + q - } - - def y(x: X1) = { - val i2 = new I2 { val q = x.s } // allowed as of SI-7571 - i2.z - - { case x => x } : PartialFunction[Int, Int] // allowed - } -} - -class X2(val s: String) extends AnyVal { - private[this] class I2(val q: String) - - def y(i: Int) = { - val i2 = new I2(i.toString) - i2.q + s - } -} |