Skip to content

Commit b6ba7ea

Browse files
committed
Merge pull request scala#2839 from densh/topic/si-7757
SI-7757 disallow constructor annotations on traits
2 parents 5084b74 + a721df7 commit b6ba7ea

File tree

5 files changed

+12
-1
lines changed

5 files changed

+12
-1
lines changed

src/compiler/scala/tools/nsc/ast/parser/Parsers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2693,7 +2693,7 @@ self =>
26932693
syntaxError("traits cannot have type parameters with context bounds `: ...' nor view bounds `<% ...'", skipIt = false)
26942694
classContextBounds = List()
26952695
}
2696-
val constrAnnots = constructorAnnotations()
2696+
val constrAnnots = if (!mods.isTrait) constructorAnnotations() else Nil
26972697
val (constrMods, vparamss) =
26982698
if (mods.isTrait) (Modifiers(Flags.TRAIT), List())
26992699
else (accessModifierOpt(), paramClauses(name, classContextBounds, ofCaseClass = mods.isCase))

test/files/neg/t7757a.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
t7757a.scala:1: error: ';' expected but '@' found.
2+
trait Foo @annot
3+
^
4+
one error found

test/files/neg/t7757a.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
trait Foo @annot

test/files/neg/t7757b.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
t7757b.scala:2: error: expected start of definition
2+
@annot2
3+
^
4+
one error found

test/files/neg/t7757b.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
trait Foo2
2+
@annot2

0 commit comments

Comments
 (0)