diff options
author | Simon Ochsenreither <simon@ochsenreither.de> | 2013-12-09 01:12:55 +0100 |
---|---|---|
committer | Simon Ochsenreither <simon@ochsenreither.de> | 2013-12-09 01:12:55 +0100 |
commit | ea8ae48c18eb558ac9e9bbf6a131ebeeec72dbdb (patch) | |
tree | 4ce75002c6710e6f6d82e4747baba3a7c5e29390 /src/compiler | |
parent | d938f59e40e7ba97b199e5f70f252d191c19d93e (diff) | |
download | scala-ea8ae48c18eb558ac9e9bbf6a131ebeeec72dbdb.tar.gz scala-ea8ae48c18eb558ac9e9bbf6a131ebeeec72dbdb.tar.bz2 scala-ea8ae48c18eb558ac9e9bbf6a131ebeeec72dbdb.zip |
SI-8052 Disallow `macro` as an identifier
Note that the change could look a lot cleaner, at the cost of returning
more generic error messages. I decided that at least for 2.11 I'll keep
scalac remembering that macro was a standard identifier name once, so
that we can point out more precisely what's wrong with users' code.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/Parsers.scala | 7 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/Scanners.scala | 8 |
2 files changed, 11 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index 91db1bb92a..61ea9230a7 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -671,6 +671,7 @@ self => def isRawBar = isIdent && in.name == raw.BAR def isIdent = in.token == IDENTIFIER || in.token == BACKQUOTED_IDENT + def isMacro = in.token == IDENTIFIER && in.name == nme.MACROkw def isLiteralToken(token: Token) = token match { case CHARLIT | INTLIT | LONGLIT | FLOATLIT | DOUBLELIT | @@ -1038,6 +1039,8 @@ self => def identForType(): TypeName = ident().toTypeName def identForType(skipIt: Boolean): TypeName = ident(skipIt).toTypeName + def identOrMacro(): Name = if (isMacro) rawIdent() else ident() + def selector(t: Tree): Tree = { val point = in.offset //assert(t.pos.isDefined, t) @@ -2551,7 +2554,7 @@ self => } else { val nameOffset = in.offset - val name = ident() + val name = identOrMacro() funDefRest(start, nameOffset, mods, name) } } @@ -2584,7 +2587,7 @@ self => } else { if (in.token == EQUALS) { in.nextTokenAllow(nme.MACROkw) - if (in.token == IDENTIFIER && in.name == nme.MACROkw) { + if (isMacro) { in.nextToken() newmods |= Flags.MACRO } diff --git a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala index b12be1a056..e488166169 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala @@ -204,8 +204,12 @@ trait Scanners extends ScannersCommon { val idx = name.start - kwOffset if (idx >= 0 && idx < kwArray.length) { token = kwArray(idx) - if (token == IDENTIFIER && allowIdent != name && emitIdentifierDeprecationWarnings) - deprecationWarning(name+" is now a reserved word; usage as an identifier is deprecated") + if (token == IDENTIFIER && allowIdent != name) { + if (name == nme.MACROkw) + syntaxError(name+" is now a reserved word; usage as an identifier is disallowed") + else if (emitIdentifierDeprecationWarnings) + deprecationWarning(name+" is now a reserved word; usage as an identifier is deprecated") + } } } } |