Skip to content

Commit

Permalink
Fix scala#13440: Avoid capturing var in message closure
Browse files Browse the repository at this point in the history
  • Loading branch information
griggt committed Sep 2, 2021
1 parent 13250bc commit 981cae4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/parsing/Scanners.scala
Expand Up @@ -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), "`")
Expand Down
4 changes: 4 additions & 0 deletions 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
3 changes: 3 additions & 0 deletions 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

0 comments on commit 981cae4

Please sign in to comment.