Skip to content

Commit 864be7c

Browse files
committed
Deprecate = _ under source 3.1
1 parent b6d0733 commit 864be7c

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3212,9 +3212,14 @@ object Parsers {
32123212
val rhs =
32133213
if tpt.isEmpty || in.token == EQUALS then
32143214
accept(EQUALS)
3215+
val rhsOffset = in.offset
32153216
subExpr() match
32163217
case rhs0 @ Ident(name) if placeholderParams.nonEmpty && name == placeholderParams.head.name
32173218
&& !tpt.isEmpty && mods.is(Mutable) && lhs.forall(_.isInstanceOf[Ident]) =>
3219+
if sourceVersion.isAtLeast(`3.1`) then
3220+
deprecationWarning(
3221+
em"""`= _` has been deprecated; use `= notInitialized` instead.
3222+
|`notInitialized` needs to be imported from scala.compiletime""", rhsOffset)
32183223
placeholderParams = placeholderParams.tail
32193224
atSpan(rhs0.span) { Ident(nme.WILDCARD) }
32203225
case rhs0 => rhs0

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class CompilationTests {
119119
aggregateTests(
120120
compileFilesInDir("tests/neg", defaultOptions),
121121
compileFilesInDir("tests/neg-tailcall", defaultOptions),
122-
compileFilesInDir("tests/neg-strict", defaultOptions.and("-source", "3.1", "-Xfatal-warnings")),
122+
compileFilesInDir("tests/neg-strict", defaultOptions.and("-source", "3.1", "-deprecation", "-Xfatal-warnings")),
123123
compileFilesInDir("tests/neg-no-kind-polymorphism", defaultOptions and "-Yno-kind-polymorphism"),
124124
compileFilesInDir("tests/neg-custom-args/deprecation", defaultOptions.and("-Xfatal-warnings", "-deprecation")),
125125
compileFilesInDir("tests/neg-custom-args/fatal-warnings", defaultOptions.and("-Xfatal-warnings")),

tests/neg-strict/i1050.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ object Tiark3 {
7474
def brand(x: Any): p.L = x // error: underlying not concrete
7575
}
7676
trait V extends U {
77-
type X = B with A
77+
type X = B & A
7878
def p2: X = ???
7979
}
8080
val v = new V {}

tests/neg-strict/i11225.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import compiletime.notInitialized
2+
3+
class Memo[A](x: => A):
4+
private var cached: A = _ // error
5+
private var known: Boolean = false
6+
def force =
7+
if !known then
8+
known = true
9+
cached = x
10+
cached

tests/neg-strict/nullless.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ object bar {
2929
type U = UU
3030
}
3131
final lazy val nothing: Nothing = nothing
32-
final lazy val sub: S2 with Sub = nothing
33-
final lazy val box : Box[S2 with Sub] = new Box(nothing)
32+
final lazy val sub: S2 & Sub = nothing
33+
final lazy val box : Box[S2 & Sub] = new Box(nothing)
3434
def upcast(t: box.v.M2): box.v.M2 = t // error // error under -strict
3535
}
3636
def main(args : Array[String]) : Unit = {

0 commit comments

Comments
 (0)