Skip to content

Commit 95253d2

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 95253d2

File tree

7 files changed

+31
-9
lines changed

7 files changed

+31
-9
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

sbt-test/compilerReporter/i14576/Test.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,5 @@ object Test:
1010
def f(x: Text) = println(x.str)
1111
f("abc")
1212

13-
// private[this] and = _ are deprecated under -source:future
14-
private[this] var x: AnyRef = _
15-
1613
// under -source:future, `_` is deprecated for wildcard arguments of types: use `?` instead
1714
val xs: List[_] = Nil

sbt-test/compilerReporter/i14576/build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ lazy val root = (project in file("."))
2424
},
2525
assertDeprecationSummary := {
2626
assert {
27-
FakePrintWriter.messages.exists(_.contains("there were 3 deprecation warnings; re-run with -deprecation for details"))
27+
FakePrintWriter.messages.exists(_.contains("there was 1 deprecation warning; re-run with -deprecation for details"))
2828
}
2929
},
3030
assertNoDeprecationSummary := {
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)