Skip to content

Commit

Permalink
Make uninitialized var syntax a migration warning
Browse files Browse the repository at this point in the history
* In `future-migration` we emit the deprecation warning
* In `future` we emit we make this syntax an error
  • Loading branch information
nicolasstucki committed Nov 1, 2023
1 parent 1e95432 commit e448e37
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
10 changes: 5 additions & 5 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3654,11 +3654,11 @@ object Parsers {
subExpr() match
case rhs0 @ Ident(name) if placeholderParams.nonEmpty && name == placeholderParams.head.name
&& !tpt.isEmpty && mods.is(Mutable) && lhs.forall(_.isInstanceOf[Ident]) =>
if sourceVersion.isAtLeast(future) then
deprecationWarning(
em"""`= _` has been deprecated; use `= uninitialized` instead.
|`uninitialized` can be imported with `scala.compiletime.uninitialized`.""",
rhsOffset)
report.errorOrMigrationWarning(
em"""`= _` has been deprecated; use `= uninitialized` instead.
|`uninitialized` can be imported with `scala.compiletime.uninitialized`.""",
in.sourcePos(rhsOffset),
from = future)
placeholderParams = placeholderParams.tail
atSpan(rhs0.span) { Ident(nme.WILDCARD) }
case rhs0 => rhs0
Expand Down
5 changes: 5 additions & 0 deletions tests/neg/uninitialized-future-migration.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Error: tests/neg/uninitialized-future-migration.scala:7:15 ----------------------------------------------------------
7 | var a: Int = _ // error
| ^
| `= _` has been deprecated; use `= uninitialized` instead.
| `uninitialized` can be imported with `scala.compiletime.uninitialized`.
8 changes: 8 additions & 0 deletions tests/neg/uninitialized-future-migration.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//> using options -Werror

import scala.language.`future-migration`
import scala.compiletime.uninitialized

class Foo:
var a: Int = _ // error
var b: Int = uninitialized
6 changes: 6 additions & 0 deletions tests/neg/uninitialized-future.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import scala.language.future
import scala.compiletime.uninitialized

class Foo:
var a: Int = _ // error
var b: Int = uninitialized
6 changes: 6 additions & 0 deletions tests/pos/uninitialized-future-migration.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import scala.language.`future-migration`
import scala.compiletime.uninitialized

class Foo:
var a: Int = _ // warn
var b: Int = uninitialized

0 comments on commit e448e37

Please sign in to comment.