Skip to content

Fix #13440: Avoid capturing var in message closure #13441

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/parsing/Scanners.scala
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import language.`3.0-migration`

case class A(enum: List[Int] = Nil) // error