Skip to content

Commit 6a3cd1f

Browse files
Merge pull request #13441 from griggt/fix-13440
Fix #13440: Avoid capturing var in message closure
2 parents 0125b46 + 8871451 commit 6a3cd1f

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

compiler/src/dotty/tools/dotc/parsing/Scanners.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,9 @@ object Scanners {
247247
else keyword
248248

249249
private def treatAsIdent(): Token =
250+
val name0 = name // don't capture the `name` var in the message closure, it may be null later
250251
report.errorOrMigrationWarning(
251-
i"$name is now a keyword, write `$name` instead of $name to keep it as an identifier",
252+
i"$name0 is now a keyword, write `$name0` instead of $name0 to keep it as an identifier",
252253
sourcePos())
253254
patch(source, Span(offset), "`")
254255
patch(source, Span(offset + name.length), "`")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Error: tests/neg-custom-args/fatal-warnings/i13440.scala:3:13 -------------------------------------------------------
2+
3 |case class A(enum: List[Int] = Nil) // error
3+
| ^
4+
| enum is now a keyword, write `enum` instead of enum to keep it as an identifier
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import language.`3.0-migration`
2+
3+
case class A(enum: List[Int] = Nil) // error

0 commit comments

Comments
 (0)