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
}

0 commit comments

Comments
 (0)