summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDen Shabalin <den.shabalin@gmail.com>2013-08-16 12:17:22 +0200
committerDen Shabalin <den.shabalin@gmail.com>2013-08-16 12:22:59 +0200
commit213116631aa2e338e09b6f6de93f8e9ef216ce14 (patch)
treec99b54ff511eb2a084d6b0700c9d6f3c3e9b2e05
parentf17fb5eaa545490c761acd4f6979a619f919ac86 (diff)
downloadscala-213116631aa2e338e09b6f6de93f8e9ef216ce14.tar.gz
scala-213116631aa2e338e09b6f6de93f8e9ef216ce14.tar.bz2
scala-213116631aa2e338e09b6f6de93f8e9ef216ce14.zip
SI-7757 disallow constructor annotations on traits
Previously it was possible to define constructor annotations on traits with really weird side-effects (parser lost the body of the trait). Now constructor annotations on traits will cause appropriate syntax errors.
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Parsers.scala2
-rw-r--r--test/files/neg/t7757.check4
-rw-r--r--test/files/neg/t7757.scala1
3 files changed, 6 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
index d0b0c09d59..a4093f9afa 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
@@ -2665,7 +2665,7 @@ self =>
syntaxError("traits cannot have type parameters with context bounds `: ...' nor view bounds `<% ...'", skipIt = false)
classContextBounds = List()
}
- val constrAnnots = constructorAnnotations()
+ val constrAnnots = if (!mods.isTrait) constructorAnnotations() else Nil
val (constrMods, vparamss) =
if (mods.isTrait) (Modifiers(Flags.TRAIT), List())
else (accessModifierOpt(), paramClauses(name, classContextBounds, ofCaseClass = mods.isCase))
diff --git a/test/files/neg/t7757.check b/test/files/neg/t7757.check
new file mode 100644
index 0000000000..8790cbc428
--- /dev/null
+++ b/test/files/neg/t7757.check
@@ -0,0 +1,4 @@
+t7757.scala:1: error: ';' expected but '@' found.
+trait Foo @annot
+ ^
+one error found
diff --git a/test/files/neg/t7757.scala b/test/files/neg/t7757.scala
new file mode 100644
index 0000000000..24f6c16cb4
--- /dev/null
+++ b/test/files/neg/t7757.scala
@@ -0,0 +1 @@
+trait Foo @annot \ No newline at end of file