From ced74110348d550c3870ac76ef067b151e97b237 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Thu, 13 Dec 2012 00:46:06 +0100 Subject: the scanner is now less eager about deprecations 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 https://github.com/scala/scala/pull/1807. Original commit is https://github.com/scala/scala/commit/e5d34d70499504e085ddf957c1c818ffb63f4e8d. --- src/compiler/scala/tools/nsc/ast/parser/Scanners.scala | 11 ++++++++++- test/files/neg/macro-false-deprecation-warning.check | 4 ++++ test/files/neg/macro-false-deprecation-warning.flags | 1 + .../macro-false-deprecation-warning/Impls_Macros_1.scala | 15 +++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 test/files/neg/macro-false-deprecation-warning.check create mode 100644 test/files/neg/macro-false-deprecation-warning.flags create mode 100644 test/files/neg/macro-false-deprecation-warning/Impls_Macros_1.scala diff --git a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala index 4f564c5d0b..00d4d57b34 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala @@ -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) @@ -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") } } @@ -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) {} } } diff --git a/test/files/neg/macro-false-deprecation-warning.check b/test/files/neg/macro-false-deprecation-warning.check new file mode 100644 index 0000000000..7d56505ec4 --- /dev/null +++ b/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 diff --git a/test/files/neg/macro-false-deprecation-warning.flags b/test/files/neg/macro-false-deprecation-warning.flags new file mode 100644 index 0000000000..cd66464f2f --- /dev/null +++ b/test/files/neg/macro-false-deprecation-warning.flags @@ -0,0 +1 @@ +-language:experimental.macros \ No newline at end of file diff --git a/test/files/neg/macro-false-deprecation-warning/Impls_Macros_1.scala b/test/files/neg/macro-false-deprecation-warning/Impls_Macros_1.scala new file mode 100644 index 0000000000..6dc2ea114b --- /dev/null +++ b/test/files/neg/macro-false-deprecation-warning/Impls_Macros_1.scala @@ -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] + } +} -- cgit v1.2.3 From 4b39be4b9ce9f93f210994906da814219a64fce1 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Fri, 28 Dec 2012 09:23:43 +0100 Subject: changes the flags to not depend on partest Due to some reason, partest always enables -deprecation. Since Paul has just submitted a pull request, which removes this behavior, I'm updating the flags to make sure this test works even after Paul's change. Backport from https://github.com/scala/scala/pull/1807 Original commit is https://github.com/scala/scala/commit/2015ad3ebd833225e93ed19604760a6da2522bb1 --- test/files/neg/macro-false-deprecation-warning.flags | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/files/neg/macro-false-deprecation-warning.flags b/test/files/neg/macro-false-deprecation-warning.flags index cd66464f2f..59af162db6 100644 --- a/test/files/neg/macro-false-deprecation-warning.flags +++ b/test/files/neg/macro-false-deprecation-warning.flags @@ -1 +1 @@ --language:experimental.macros \ No newline at end of file +-language:experimental.macros -deprecation \ No newline at end of file -- cgit v1.2.3