Skip to content

Commit 3b6b55f

Browse files
committed
Add rewrite rule for var x: T = _
1 parent e448e37 commit 3b6b55f

File tree

5 files changed

+9
-1
lines changed

5 files changed

+9
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3656,9 +3656,11 @@ object Parsers {
36563656
&& !tpt.isEmpty && mods.is(Mutable) && lhs.forall(_.isInstanceOf[Ident]) =>
36573657
report.errorOrMigrationWarning(
36583658
em"""`= _` has been deprecated; use `= uninitialized` instead.
3659-
|`uninitialized` can be imported with `scala.compiletime.uninitialized`.""",
3659+
|`uninitialized` can be imported with `scala.compiletime.uninitialized`.${rewriteNotice(`future-migration`)}""",
36603660
in.sourcePos(rhsOffset),
36613661
from = future)
3662+
if sourceVersion == `future-migration` then
3663+
patch(source, Span(rhsOffset, rhsOffset + 1), "scala.compiletime.uninitialized")
36623664
placeholderParams = placeholderParams.tail
36633665
atSpan(rhs0.span) { Ident(nme.WILDCARD) }
36643666
case rhs0 => rhs0

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class CompilationTests {
6060
compileFile("tests/rewrites/rewrites.scala", defaultOptions.and("-source", "3.0-migration").and("-rewrite", "-indent")),
6161
compileFile("tests/rewrites/rewrites3x.scala", defaultOptions.and("-rewrite", "-source", "future-migration")),
6262
compileFile("tests/rewrites/rewrites3x-fatal-warnings.scala", defaultOptions.and("-rewrite", "-source", "future-migration", "-Xfatal-warnings")),
63+
compileFile("tests/rewrites/uninitialized-var.scala", defaultOptions.and("-rewrite", "-source", "future-migration")),
6364
compileFile("tests/rewrites/filtering-fors.scala", defaultOptions.and("-rewrite", "-source", "3.2-migration")),
6465
compileFile("tests/rewrites/refutable-pattern-bindings.scala", defaultOptions.and("-rewrite", "-source", "3.2-migration")),
6566
compileFile("tests/rewrites/i8982.scala", defaultOptions.and("-indent", "-rewrite")),

tests/neg/uninitialized-future-migration.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
| ^
44
| `= _` has been deprecated; use `= uninitialized` instead.
55
| `uninitialized` can be imported with `scala.compiletime.uninitialized`.
6+
| This construct can be rewritten automatically under -rewrite -source future-migration.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class Foo:
2+
var a: Int = scala.compiletime.uninitialized
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class Foo:
2+
var a: Int = _

0 commit comments

Comments
 (0)