Skip to content

Commit

Permalink
Add rewrite rule for var x: T = _
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Nov 2, 2023
1 parent a825cf9 commit 0343a75
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3656,9 +3656,11 @@ object Parsers {
&& !tpt.isEmpty && mods.is(Mutable) && lhs.forall(_.isInstanceOf[Ident]) =>
report.errorOrMigrationWarning(
em"""`= _` has been deprecated; use `= uninitialized` instead.
|`uninitialized` can be imported with `scala.compiletime.uninitialized`.""",
|`uninitialized` can be imported with `scala.compiletime.uninitialized`.${rewriteNotice(`future-migration`)}""",
in.sourcePos(rhsOffset),
from = future)
if sourceVersion == `future-migration` then
patch(source, Span(rhsOffset, rhsOffset + 1), "scala.compiletime.uninitialized")
placeholderParams = placeholderParams.tail
atSpan(rhs0.span) { Ident(nme.WILDCARD) }
case rhs0 => rhs0
Expand Down
1 change: 1 addition & 0 deletions compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class CompilationTests {
compileFile("tests/rewrites/rewrites.scala", defaultOptions.and("-source", "3.0-migration").and("-rewrite", "-indent")),
compileFile("tests/rewrites/rewrites3x.scala", defaultOptions.and("-rewrite", "-source", "future-migration")),
compileFile("tests/rewrites/rewrites3x-fatal-warnings.scala", defaultOptions.and("-rewrite", "-source", "future-migration", "-Xfatal-warnings")),
compileFile("tests/rewrites/uninitialized-var.scala", defaultOptions.and("-rewrite", "-source", "future-migration")),
compileFile("tests/rewrites/with-type-operator.scala", defaultOptions.and("-rewrite", "-source", "future-migration")),
compileFile("tests/rewrites/filtering-fors.scala", defaultOptions.and("-rewrite", "-source", "3.2-migration")),
compileFile("tests/rewrites/refutable-pattern-bindings.scala", defaultOptions.and("-rewrite", "-source", "3.2-migration")),
Expand Down
1 change: 1 addition & 0 deletions tests/neg/uninitialized-future-migration.check
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
| ^
| `= _` has been deprecated; use `= uninitialized` instead.
| `uninitialized` can be imported with `scala.compiletime.uninitialized`.
| This construct can be rewritten automatically under -rewrite -source future-migration.
2 changes: 2 additions & 0 deletions tests/rewrites/uninitialized-var.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Foo:
var a: Int = scala.compiletime.uninitialized
2 changes: 2 additions & 0 deletions tests/rewrites/uninitialized-var.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Foo:
var a: Int = _

0 comments on commit 0343a75

Please sign in to comment.