Skip to content

Commit 493082b

Browse files
committed
Change tests to new syntax
Fix recognition of uniniialized if type of var is a context function. This required a special case in typedValDef for `var x: A ?=> B = _`. Now it requires a special case in `PruneErasedDefs` in `var x: A ?=> B = undefined`.
1 parent 5543550 commit 493082b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+133
-115
lines changed

bench/tests/Vector.scala

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import scala.annotation.unchecked.uncheckedVariance
1414
import scala.compat.Platform
1515
import scala.collection.generic._
1616
import scala.collection.mutable.Builder
17+
import compiletime.uninitialized
1718

1819
/** Companion object to the Vector class
1920
*/
@@ -741,13 +742,13 @@ final class VectorBuilder[A]() extends Builder[A,Vector[A]] with VectorPointer[A
741742

742743

743744
private[immutable] trait VectorPointer[T] {
744-
private[immutable] var depth: Int = _
745-
private[immutable] var display0: Array[AnyRef] = _
746-
private[immutable] var display1: Array[AnyRef] = _
747-
private[immutable] var display2: Array[AnyRef] = _
748-
private[immutable] var display3: Array[AnyRef] = _
749-
private[immutable] var display4: Array[AnyRef] = _
750-
private[immutable] var display5: Array[AnyRef] = _
745+
private[immutable] var depth: Int = uninitialized
746+
private[immutable] var display0: Array[AnyRef] = uninitialized
747+
private[immutable] var display1: Array[AnyRef] = uninitialized
748+
private[immutable] var display2: Array[AnyRef] = uninitialized
749+
private[immutable] var display3: Array[AnyRef] = uninitialized
750+
private[immutable] var display4: Array[AnyRef] = uninitialized
751+
private[immutable] var display5: Array[AnyRef] = uninitialized
751752

752753
// used
753754
private[immutable] final def initFrom[U](that: VectorPointer[U]): Unit = initFrom(that, that.depth)

compiler/src/dotty/tools/dotc/transform/PruneErasedDefs.scala

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,25 @@ class PruneErasedDefs extends MiniPhase with SymTransformer { thisTransform =>
4343
cpy.Apply(tree)(tree.fun, tree.args.map(trivialErasedTree))
4444
else tree
4545

46+
private def hasUninitializedRHS(tree: ValOrDefDef)(using Context): Boolean =
47+
def recur(rhs: Tree): Boolean = rhs match
48+
case rhs: RefTree =>
49+
rhs.symbol == defn.Compiletime_uninitialized
50+
&& tree.symbol.is(Mutable) && tree.symbol.owner.isClass
51+
case closureDef(ddef) if defn.isContextFunctionType(tree.tpt.tpe.dealias) =>
52+
recur(ddef.rhs)
53+
case _ =>
54+
false
55+
recur(tree.rhs)
56+
4657
override def transformValDef(tree: ValDef)(using Context): Tree =
4758
val sym = tree.symbol
48-
if sym.isEffectivelyErased && !tree.rhs.isEmpty then
59+
if tree.symbol.isEffectivelyErased && !tree.rhs.isEmpty then
4960
cpy.ValDef(tree)(rhs = trivialErasedTree(tree))
50-
else tree.rhs match
51-
case rhs: RefTree
52-
if rhs.symbol == defn.Compiletime_uninitialized
53-
&& sym.is(Mutable) && sym.owner.isClass =>
54-
cpy.ValDef(tree)(rhs = cpy.Ident(rhs)(nme.WILDCARD))
55-
case _ =>
56-
tree
61+
else if hasUninitializedRHS(tree) then
62+
cpy.ValDef(tree)(rhs = cpy.Ident(tree.rhs)(nme.WILDCARD).withType(tree.tpt.tpe))
63+
else
64+
tree
5765

5866
override def transformDefDef(tree: DefDef)(using Context): Tree =
5967
if (tree.symbol.isEffectivelyErased && !tree.rhs.isEmpty)

tests/fuzzy/471d33abf565d5dd3691679237f148638f4ff115.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def i10(i2: i4): i3 = new i4(i5)
2424
object i10 {
2525
def main(i12: Array[String]): Unit = {
2626
val i10: Array[String] = null
27-
var i2 = _
27+
var i2 = compiletime.uninitialized
2828
def i3(i2: Int) = i2
2929
}
3030
object i0 {

tests/init/crash/i2468.scala

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11

2+
import compiletime.uninitialized
23
object Test {
34

45
class A {
5-
private[this] var x: String = _
6+
private[this] var x: String = uninitialized
67
}
78

89
class B {
@@ -11,16 +12,16 @@ object Test {
1112
}
1213

1314
class C {
14-
private[this] var x1: Int = _
15-
private[this] var x2: Unit = _
16-
private[this] var x3: Char = _
17-
private[this] var x4: Boolean = _
18-
private[this] var x5: Float = _
19-
private[this] var x6: Double = _
20-
private[this] var x7: Char = _
21-
private[this] var x8: Byte = _
22-
private[this] var x9: AnyVal = _
23-
private[this] var x10: D = _
15+
private[this] var x1: Int = uninitialized
16+
private[this] var x2: Unit = uninitialized
17+
private[this] var x3: Char = uninitialized
18+
private[this] var x4: Boolean = uninitialized
19+
private[this] var x5: Float = uninitialized
20+
private[this] var x6: Double = uninitialized
21+
private[this] var x7: Char = uninitialized
22+
private[this] var x8: Byte = uninitialized
23+
private[this] var x9: AnyVal = uninitialized
24+
private[this] var x10: D = uninitialized
2425
}
2526

2627
class D(x: Int) extends AnyVal

tests/init/crash/opassign.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ object opassign {
1212
}
1313

1414
class Ref {
15-
var x: Int = _
15+
var x: Int = compiletime.uninitialized
1616
}
1717
val r = new Ref
1818
r.x += 1

tests/neg/i11225.check

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
6 | var x2: Int = if ??? then uninitialized else uninitialized // error // error
1111
| ^^^^^^^^^^^^^
1212
| `uninitialized` can only be used as the right hand side of a mutable field definition
13-
-- Error: tests/neg/i11225.scala:7:29 ----------------------------------------------------------------------------------
14-
7 | var x3: Int = if true then uninitialized else 1 // error
15-
| ^^^^^^^^^^^^^
16-
| `uninitialized` can only be used as the right hand side of a mutable field definition
1713
-- Error: tests/neg/i11225.scala:9:28 ----------------------------------------------------------------------------------
1814
9 | var x5: () => Int = () => uninitialized // error
1915
| ^^^^^^^^^^^^^

tests/neg/i11225.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ class Test:
44

55
val x1: Int = uninitialized // error
66
var x2: Int = if ??? then uninitialized else uninitialized // error // error
7-
var x3: Int = if true then uninitialized else 1 // error
8-
var x4: Int = if false then uninitialized else 1 // ok, since inlined away
7+
var x3: Int = if true then uninitialized else 1 // ok
8+
var x4: Int = if false then uninitialized else 1 // ok
99
var x5: () => Int = () => uninitialized // error
1010
var x6: Int = { uninitialized } // error
1111

tests/neg/i8427.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
trait T
33

44
object Test {
5-
var t: T = _
5+
var t: T = compiletime.uninitialized
66
def main(args: Array[String]) = println("hi")
77
}

tests/neg/refinedSubtyping.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Test3 {
1313
type U1 = C { type T <: B }
1414
type U2 = C { type T <: A }
1515

16-
var x: T2 = _
16+
var x: T2 = compiletime.uninitialized
1717
val y1: U1 = ???
1818
val y2: U2 = ???
1919

tests/neg/t11437.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
class Regress {
3-
var v: Int = _
3+
var v: Int = compiletime.uninitialized
44
def f = 42
55
var w: Int = (_) // error: not default value syntax
66
}

tests/neg/tcpoly_variance_enforce.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ object fcoll4_2 extends coll4[FooString, Any] // error
3232

3333

3434
object test {
35-
var ok: coll[FooCov] = _
35+
var ok: coll[FooCov] = compiletime.uninitialized
3636

3737
def x: coll[FooInvar] = sys.error("foo") // error
3838
def y: coll[FooContra] = sys.error("foo") // error

tests/neg/variances-constr.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class C[+A] {
22

3-
private[this] var y: A = _
3+
private[this] var y: A = compiletime.uninitialized
44
def getY: A = y
55

66
class Inner(x: A) { // error A appears contravariantly
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// also test pickling of java annotations; Test_2.scala will
22
// read this class file
33
@Ann(nested = Array(new Ann2(10))) class Test {
4-
@Ann2(100) var ctx: Object = _
4+
@Ann2(100) var ctx: Object = compiletime.uninitialized
55
@Ann(nested = Array()) def foo = 10
66
@Ann(nested = Array(new Ann2(10), new Ann2(23))) val bam = -3
77
}

tests/pos-special/strawman-collections/CollectionStrawMan4.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ object CollectionStrawMan4 {
463463
-1
464464
}
465465
def filter(p: A => Boolean): Iterator[A] = new Iterator[A] {
466-
private var hd: A = _
466+
private var hd: A = compiletime.uninitialized
467467
private var hdDefined: Boolean = false
468468

469469
def hasNext: Boolean = hdDefined || {

tests/pos-special/strawman-collections/CollectionStrawMan5.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ object CollectionStrawMan5 {
445445
-1
446446
}
447447
def filter(p: A => Boolean): Iterator[A] = new Iterator[A] {
448-
private var hd: A = _
448+
private var hd: A = compiletime.uninitialized
449449
private var hdDefined: Boolean = false
450450

451451
def hasNext: Boolean = hdDefined || {

tests/pos-special/strawman-collections/CollectionStrawMan6.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Predef.{augmentString => _, wrapString => _, _}
44
import scala.reflect.ClassTag
55
import annotation.unchecked.uncheckedVariance
66
import annotation.tailrec
7+
import compiletime.uninitialized
78

89
class LowPriority {
910
import CollectionStrawMan6._
@@ -606,7 +607,7 @@ object CollectionStrawMan6 extends LowPriority {
606607
class LazyList[+A](expr: => LazyList.Evaluated[A])
607608
extends LinearSeq[A] with LinearSeqLike[A, LazyList] {
608609
private[this] var evaluated = false
609-
private[this] var result: LazyList.Evaluated[A] = _
610+
private[this] var result: LazyList.Evaluated[A] = uninitialized
610611

611612
def force: LazyList.Evaluated[A] = {
612613
if (!evaluated) {
@@ -960,7 +961,7 @@ object CollectionStrawMan6 extends LowPriority {
960961
len
961962
}
962963
def filter(p: A => Boolean): Iterator[A] = new Iterator[A] {
963-
private var hd: A = _
964+
private var hd: A = uninitialized
964965
private var hdDefined: Boolean = false
965966

966967
def hasNext: Boolean = hdDefined || {

tests/pos/Transactions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ object Transaction {
2020
}
2121

2222
class Transaction {
23-
var status: Int = _
23+
var status: Int = compiletime.uninitialized
2424

2525
var id: Long = _ // only for real transactions
2626

tests/pos/apply-equiv.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
class Test {
2+
import compiletime.uninitialized
23

34
class Lambda { type Arg; type Apply }
45

56
type T1 = (Lambda { type Arg = Int } { type Apply = List[Arg] }) # Apply
67
type T2 = List[Int]
78

8-
var x: T1 = _
9-
var y: T2 = _
9+
var x: T1 = uninitialized
10+
var y: T2 = uninitialized
1011

1112
x = y
1213
y = x

tests/pos/capturedVars.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class Test {
22

3-
var field: Int = _
3+
var field: Int = compiletime.uninitialized
44

55
def foo() = {
66

tests/pos/constrs.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class Foo(x: Int, var y: Int) {
22

33
val z: Int = 0
44

5-
var u: Int = _
5+
var u: Int = compiletime.uninitialized
66

77
def f = x
88

tests/pos/hklower.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Test2 {
3434

3535
f[V](t)
3636

37-
var x: V[Int] = _
37+
var x: V[Int] = compiletime.uninitialized
3838
x = t
3939

4040

tests/pos/i2468.scala

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11

2+
import compiletime.uninitialized
23
object Test {
34

45
class A {
5-
private[this] var x: String = _
6+
private[this] var x: String = uninitialized
67
}
78

89
class B {
9-
private[this] var x: String = _
10+
private[this] var x: String = uninitialized
1011
x = "foo"
1112
}
1213

1314
class C {
14-
private[this] var x1: Int = _
15-
private[this] var x2: Unit = _
16-
private[this] var x3: Char = _
17-
private[this] var x4: Boolean = _
18-
private[this] var x5: Float = _
19-
private[this] var x6: Double = _
20-
private[this] var x7: Char = _
21-
private[this] var x8: Byte = _
22-
private[this] var x9: AnyVal = _
23-
private[this] var x10: D = _
15+
private[this] var x1: Int = uninitialized
16+
private[this] var x2: Unit = uninitialized
17+
private[this] var x3: Char = uninitialized
18+
private[this] var x4: Boolean = uninitialized
19+
private[this] var x5: Float = uninitialized
20+
private[this] var x6: Double = uninitialized
21+
private[this] var x7: Char = uninitialized
22+
private[this] var x8: Byte = uninitialized
23+
private[this] var x9: AnyVal = uninitialized
24+
private[this] var x10: D = uninitialized
2425
}
2526

2627
class D(x: Int) extends AnyVal

tests/pos/i9307.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import compiletime.uninitialized
12
class Foo:
2-
private var foo1: Int = _
3-
private var foo2: Array[Int] = _
4-
private[this] var foo3: Array[Int] = _
5-
private var foo4: Array[Object] = _
6-
private var foo5: Array[Array[Int]] = _
7-
private var foo6: List[Int] = _
3+
private var foo1: Int = uninitialized
4+
private var foo2: Array[Int] = uninitialized
5+
private[this] var foo3: Array[Int] = uninitialized
6+
private var foo4: Array[Object] = uninitialized
7+
private var foo5: Array[Array[Int]] = uninitialized
8+
private var foo6: List[Int] = uninitialized

tests/pos/isApplicableSafe.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import reflect.ClassTag
2-
2+
import compiletime.uninitialized
33
// The same problems arise in real arrays.
44
class A {
55

@@ -10,8 +10,8 @@ class A {
1010
}
1111

1212
// Any of Array[List[Symbol]], List[Array[Symbol]], or List[List[Symbol]] compile.
13-
var xs: Array[Array[Symbol]] = _
14-
var ys: Array[Map[Symbol, Set[Symbol]]] = _
13+
var xs: Array[Array[Symbol]] = uninitialized
14+
var ys: Array[Map[Symbol, Set[Symbol]]] = uninitialized
1515

1616
//xs = Array(Array())
1717
// gives:

tests/pos/opassign.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ object opassign {
1212
}
1313

1414
class Ref {
15-
var x: Int = _
15+
var x: Int = compiletime.uninitialized
1616
}
1717
val r = new Ref
1818
r.x += 1

tests/pos/projections.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
import compiletime.uninitialized
12
class projections {
23

34
class Lambda { type Arg; type Apply }
45

5-
var x: (Lambda { type Apply = Int; type Arg = String }) # Apply = _
6-
var y: Int = _
6+
var x: (Lambda { type Apply = Int; type Arg = String }) # Apply = uninitialized
7+
var y: Int = uninitialized
78
x = y
89
y = x
910

10-
var xx: (Lambda { type Apply = Arg } { type Arg = Int }) # Apply = _
11+
var xx: (Lambda { type Apply = Arg } { type Arg = Int }) # Apply = uninitialized
1112
xx = y
1213
y = xx
1314

0 commit comments

Comments
 (0)