Skip to content

Commit

Permalink
Disallow {...} arguments for annotations
Browse files Browse the repository at this point in the history
This mimics scalac's behavior (but not the official syntax; in fact the
official syntax seems to be ambiguous.
  • Loading branch information
odersky committed May 21, 2015
1 parent 1f908b4 commit 89145d0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/SyntaxSummary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ grammar.
AccessModifier ::= (`private' | `protected') [AccessQualifier]
AccessQualifier ::= `[' (id | `this') `]'

Annotation ::= `@' SimpleType {ArgumentExprs} Apply(tpe, args)
Annotation ::= `@' SimpleType {ParArgumentExprs} Apply(tpe, args)

TemplateBody ::= [nl] `{' [SelfType] TemplateStat {semi TemplateStat} `} (self, stats)
TemplateStat ::= Import
Expand Down
4 changes: 2 additions & 2 deletions src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1429,10 +1429,10 @@ object Parsers {
else tree1
}

/** Annotation ::= `@' SimpleType {ArgumentExprs}
/** Annotation ::= `@' SimpleType {ParArgumentExprs}
*/
def annot() =
adjustStart(accept(AT)) { ensureApplied(argumentExprss(wrapNew(simpleType()))) }
adjustStart(accept(AT)) { ensureApplied(parArgumentExprss(wrapNew(simpleType()))) }

def annotations(skipNewLines: Boolean = false): List[Tree] = {
if (skipNewLines) newLineOptWhenFollowedBy(AT)
Expand Down
13 changes: 13 additions & 0 deletions tests/pos/annot.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import java.beans.Transient
import annotation.unchecked.uncheckedVariance

class Test {

// testing combinations of annotation syntax

@SuppressWarnings(Array("hi")) def foo() = ??? // evalutation of annotation on type cannot be deferred as requires implicit resolution(only generic Array$.apply applies here)

@SuppressWarnings(Array("hi", "foo")) def foo2() = ??? //can be deferred as there is a non-generic method
Expand All @@ -11,5 +14,15 @@ class Test {
@Transient(false) def bar = ???

@Transient() def baz = ???

// testing annotations in types

class A
trait B

val x: A @uncheckedVariance with B @uncheckedVariance = ???

//class C extends A @uncheckedVariance () with B @uncheckedVariance { val x = 10 }

}

0 comments on commit 89145d0

Please sign in to comment.