From 88714512d399bb23156852f8f104adad0e249074 Mon Sep 17 00:00:00 2001 From: Tom Grigg Date: Wed, 1 Sep 2021 18:26:45 -0700 Subject: [PATCH] Fix #13440: Avoid capturing var in message closure --- compiler/src/dotty/tools/dotc/parsing/Scanners.scala | 3 ++- tests/neg-custom-args/fatal-warnings/i13440.check | 4 ++++ tests/neg-custom-args/fatal-warnings/i13440.scala | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 tests/neg-custom-args/fatal-warnings/i13440.check create mode 100644 tests/neg-custom-args/fatal-warnings/i13440.scala diff --git a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala index 61e31ff1dce8..84a181769e3b 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala @@ -247,8 +247,9 @@ object Scanners { else keyword private def treatAsIdent(): Token = + val name0 = name // don't capture the `name` var in the message closure, it may be null later report.errorOrMigrationWarning( - i"$name is now a keyword, write `$name` instead of $name to keep it as an identifier", + i"$name0 is now a keyword, write `$name0` instead of $name0 to keep it as an identifier", sourcePos()) patch(source, Span(offset), "`") patch(source, Span(offset + name.length), "`") diff --git a/tests/neg-custom-args/fatal-warnings/i13440.check b/tests/neg-custom-args/fatal-warnings/i13440.check new file mode 100644 index 000000000000..0e9dd7dd5e50 --- /dev/null +++ b/tests/neg-custom-args/fatal-warnings/i13440.check @@ -0,0 +1,4 @@ +-- Error: tests/neg-custom-args/fatal-warnings/i13440.scala:3:13 ------------------------------------------------------- +3 |case class A(enum: List[Int] = Nil) // error + | ^ + | enum is now a keyword, write `enum` instead of enum to keep it as an identifier diff --git a/tests/neg-custom-args/fatal-warnings/i13440.scala b/tests/neg-custom-args/fatal-warnings/i13440.scala new file mode 100644 index 000000000000..8e3af76ad3fa --- /dev/null +++ b/tests/neg-custom-args/fatal-warnings/i13440.scala @@ -0,0 +1,3 @@ +import language.`3.0-migration` + +case class A(enum: List[Int] = Nil) // error