Skip to content

Commit e448e37

Browse files
committed
Make uninitialized var syntax a migration warning
* In `future-migration` we emit the deprecation warning * In `future` we emit we make this syntax an error
1 parent 1e95432 commit e448e37

File tree

5 files changed

+30
-5
lines changed

5 files changed

+30
-5
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3654,11 +3654,11 @@ object Parsers {
36543654
subExpr() match
36553655
case rhs0 @ Ident(name) if placeholderParams.nonEmpty && name == placeholderParams.head.name
36563656
&& !tpt.isEmpty && mods.is(Mutable) && lhs.forall(_.isInstanceOf[Ident]) =>
3657-
if sourceVersion.isAtLeast(future) then
3658-
deprecationWarning(
3659-
em"""`= _` has been deprecated; use `= uninitialized` instead.
3660-
|`uninitialized` can be imported with `scala.compiletime.uninitialized`.""",
3661-
rhsOffset)
3657+
report.errorOrMigrationWarning(
3658+
em"""`= _` has been deprecated; use `= uninitialized` instead.
3659+
|`uninitialized` can be imported with `scala.compiletime.uninitialized`.""",
3660+
in.sourcePos(rhsOffset),
3661+
from = future)
36623662
placeholderParams = placeholderParams.tail
36633663
atSpan(rhs0.span) { Ident(nme.WILDCARD) }
36643664
case rhs0 => rhs0
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- Error: tests/neg/uninitialized-future-migration.scala:7:15 ----------------------------------------------------------
2+
7 | var a: Int = _ // error
3+
| ^
4+
| `= _` has been deprecated; use `= uninitialized` instead.
5+
| `uninitialized` can be imported with `scala.compiletime.uninitialized`.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//> using options -Werror
2+
3+
import scala.language.`future-migration`
4+
import scala.compiletime.uninitialized
5+
6+
class Foo:
7+
var a: Int = _ // error
8+
var b: Int = uninitialized

tests/neg/uninitialized-future.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import scala.language.future
2+
import scala.compiletime.uninitialized
3+
4+
class Foo:
5+
var a: Int = _ // error
6+
var b: Int = uninitialized
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import scala.language.`future-migration`
2+
import scala.compiletime.uninitialized
3+
4+
class Foo:
5+
var a: Int = _ // warn
6+
var b: Int = uninitialized

0 commit comments

Comments
 (0)