Skip to content

Commit

Permalink
the scanner is now less eager about deprecations
Browse files Browse the repository at this point in the history
When healing braces it isn't very useful to report deprecation warnings,
especially since this process is just simple context-free skimming, which
can't know about what positions can accept what identifiers.

Backport from #1807.
Original commit is e5d34d7.
  • Loading branch information
xeno-by committed Jan 31, 2013
1 parent 2fa859e commit ced7411
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/compiler/scala/tools/nsc/ast/parser/Scanners.scala
Expand Up @@ -113,6 +113,11 @@ trait Scanners extends ScannersCommon {
cbuf.append(c)
}

/** Determines whether this scanner should emit identifier deprecation warnings,
* e.g. when seeing `macro` or `then`, which are planned to become keywords in future versions of Scala.
*/
protected def emitIdentifierDeprecationWarnings = true

/** Clear buffer and set name and token */
private def finishNamed(idtoken: Int = IDENTIFIER) {
name = newTermName(cbuf.toString)
Expand All @@ -122,7 +127,7 @@ trait Scanners extends ScannersCommon {
val idx = name.start - kwOffset
if (idx >= 0 && idx < kwArray.length) {
token = kwArray(idx)
if (token == IDENTIFIER && allowIdent != name)
if (token == IDENTIFIER && allowIdent != name && emitIdentifierDeprecationWarnings)
deprecationWarning(name+" is now a reserved word; usage as an identifier is deprecated")
}
}
Expand Down Expand Up @@ -1488,6 +1493,10 @@ trait Scanners extends ScannersCommon {
def improves(patches1: List[BracePatch]): Boolean =
imbalanceMeasure > new ParensAnalyzer(unit, patches1).imbalanceMeasure

// don't emit deprecation warnings about identifiers like `macro` or `then`
// when skimming through the source file trying to heal braces
override def emitIdentifierDeprecationWarnings = false

override def error(offset: Int, msg: String) {}
}
}
4 changes: 4 additions & 0 deletions test/files/neg/macro-false-deprecation-warning.check
@@ -0,0 +1,4 @@
Impls_Macros_1.scala:5: error: illegal start of simple expression
}
^
one error found
1 change: 1 addition & 0 deletions test/files/neg/macro-false-deprecation-warning.flags
@@ -0,0 +1 @@
-language:experimental.macros
@@ -0,0 +1,15 @@
import scala.reflect.macros.Context

object Helper {
def unapplySeq[T](x: List[T]): Option[Seq[T]] =
}

object Macros {
def impl[T: c.WeakTypeTag](c: Context)(x: c.Expr[List[T]]) = {
c.universe.reify(Helper.unapplySeq(x.splice))
}

object UnapplyMacro {
def unapplySeq[T](x: List[T]): Option[Seq[T]] = macro impl[T]
}
}

0 comments on commit ced7411

Please sign in to comment.