Skip to content

Commit 1932b33

Browse files
committed
Tweak default: widen 1
1 parent d3357c0 commit 1932b33

File tree

4 files changed

+15
-17
lines changed

4 files changed

+15
-17
lines changed

compiler/src/dotty/tools/dotc/transform/init/Objects.scala

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -504,26 +504,24 @@ object Objects:
504504
case (a, b) => RefSet(ListSet(a, b))
505505

506506
def widen(height: Int)(using Context): Value =
507-
a match
508-
case Bottom => Bottom
507+
if height == 0 then Cold
508+
else
509+
a match
510+
case Bottom => Bottom
509511

510-
case RefSet(refs) =>
511-
refs.map(ref => ref.widen(height)).join
512+
case RefSet(refs) =>
513+
refs.map(ref => ref.widen(height)).join
512514

513-
case Fun(code, thisV, klass, env) =>
514-
if height == 0 then Cold
515-
else Fun(code, thisV.widen(height), klass, env.widen(height))
515+
case Fun(code, thisV, klass, env) =>
516+
Fun(code, thisV.widen(height), klass, env.widen(height))
516517

517-
case ref @ OfClass(klass, outer, _, args, env) =>
518-
if height == 0 then
519-
Cold
520-
else
518+
case ref @ OfClass(klass, outer, _, args, env) =>
521519
val outer2 = outer.widen(height - 1)
522520
val args2 = args.map(_.widen(height - 1))
523521
val env2 = env.widen(height - 1)
524522
ref.widenedCopy(outer2, args2, env2)
525-
case _ => a
526523

524+
case _ => a
527525

528526
extension (values: Iterable[Value])
529527
def join: Value = if values.isEmpty then Bottom else values.reduce { (v1, v2) => v1.join(v2) }
@@ -1151,7 +1149,7 @@ object Objects:
11511149
if arg.tree.tpe.hasAnnotation(defn.InitExposeAnnot) then
11521150
res.widen(1)
11531151
else
1154-
Cold
1152+
res.widen(1)
11551153

11561154
argInfos += TraceValue(widened, trace.add(arg.tree))
11571155
}

tests/init/neg/global-cycle14.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ object A { // error
1010
}
1111

1212
object B {
13-
val m: Int = A.n
13+
val m: Int = A.n // error
1414
}

tests/init/neg/global-cycle7.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ object A { // error
33
}
44

55
object B {
6-
val m: Int = A.n
6+
val m: Int = A.n // error
77
}
88

99
abstract class TokensCommon {

tests/init/neg/global-region1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import scala.annotation.init
22

33
trait B { def foo(): Int }
44
class C(var x: Int) extends B { def foo(): Int = 20 }
5-
class D(var y: Int) extends B { def foo(): Int = A.m }
5+
class D(var y: Int) extends B { def foo(): Int = A.m } // error
66
class Box(var value: B)
77

88
object A:
99
val box1: Box = new Box(new C(5): @init.expose)
1010
val box2: Box = new Box(new D(10): @init.expose)
11-
val m: Int = box1.value.foo() // error
11+
val m: Int = box1.value.foo()

0 commit comments

Comments
 (0)