diff options
author | Martin Odersky <odersky@gmail.com> | 2015-10-21 17:49:27 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2015-10-22 12:21:26 +0200 |
commit | f1b3859911ee04a90a0b169c5eefa2c64ce5d265 (patch) | |
tree | 0d8d90bc89d62a83c7bd1395ecac1e43f922bd09 /tests/neg | |
parent | 54f5899b0888983495f5ff70f561d9634350f3f2 (diff) | |
download | dotty-f1b3859911ee04a90a0b169c5eefa2c64ce5d265.tar.gz dotty-f1b3859911ee04a90a0b169c5eefa2c64ce5d265.tar.bz2 dotty-f1b3859911ee04a90a0b169c5eefa2c64ce5d265.zip |
Add well-formedness checking for created symbols
Enforces various restrictions of definitions.
Diffstat (limited to 'tests/neg')
-rw-r--r-- | tests/neg/validate-parsing.scala | 13 | ||||
-rw-r--r-- | tests/neg/validate-refchecks.scala | 13 | ||||
-rw-r--r-- | tests/neg/validate.scala | 48 |
3 files changed, 74 insertions, 0 deletions
diff --git a/tests/neg/validate-parsing.scala b/tests/neg/validate-parsing.scala new file mode 100644 index 000000000..d0eee526a --- /dev/null +++ b/tests/neg/validate-parsing.scala @@ -0,0 +1,13 @@ +object A { + sealed def y: Int = 1 // error: modifier(s) `sealed' not allowed for method + sealed var x = 1 // error: modifier(s) `sealed' not allowed for variable + lazy trait T // error: modifier(s) `lazy' not allowed for trait +} + +class C () { + implicit this() = this() // error: ';' expected but 'implicit' found. + override this() = this() // error: ';' expected but 'override' found. +} +class D override() // error: ';' expected but 'override' found. + +case class ByName(x: => Int) // error: `val' parameters may not be call-by-name diff --git a/tests/neg/validate-refchecks.scala b/tests/neg/validate-refchecks.scala new file mode 100644 index 000000000..10e61407d --- /dev/null +++ b/tests/neg/validate-refchecks.scala @@ -0,0 +1,13 @@ + +trait A { + class C {} +} + +trait B extends A { + class C {} // error: cannot override +} + +trait C extends A { + type C = Int // error: cannot override +} + diff --git a/tests/neg/validate.scala b/tests/neg/validate.scala new file mode 100644 index 000000000..38da83fd7 --- /dev/null +++ b/tests/neg/validate.scala @@ -0,0 +1,48 @@ +trait X { + type Y + abstract val v: Y // error: abstract term + abstract def y: Y // error: abstract term +} + +implicit object Z { // error: implict at toplevel + implicit case class C() // error: implicit classes may not be case classes + implicit type T = Int // error: implicit modifier cannot be used for types or traits + implicit trait U // error: implicit modifier cannot be used for types or traits + val x: X = new X { + type Y = Int + val v: Int = 1 + } + var y: Int // error: only classes can have declared but undefined members + val z: Int = { + val u: Int // error: only classes can have declared but undefined members + 1 + } +} + +trait T { + type X + def foo: Unit = { + var x: Int // error: only classes can have declared but undefined members + () + } + private def bar: Int // error: abstract member may not have private modifier + final def baz: Int // error: abstract member may not have final modifier +} + +final sealed class A { // error: illegal combination of modifiers: final and sealed + private protected def f: Int = 1 // error: illegal combination of modifiers: private and protected +} + + +class E extends T { + abstract override def foo: Unit // error: abstract override only allowed for members of traits +} + +trait U extends T { + abstract override type X // error: `abstract override' incompatible with type definition + @native def f(): Unit = 1 // error: `@native' members may not have implementation +} + +trait TT extends AnyVal // error: trait TT annot extend AnyVal + +final trait UU // error: trait UU may not be `final' |