Skip to content

Commit f2f9df3

Browse files
author
EnzeXing
committed
Update abstract domain and tests
1 parent b488a1c commit f2f9df3

File tree

10 files changed

+504
-244
lines changed

10 files changed

+504
-244
lines changed

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

Lines changed: 392 additions & 222 deletions
Large diffs are not rendered by default.
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
class Outer {
2-
val f = 5
3-
class Inner extends Outer {
4-
val g = Outer.this.f
1+
class Outer(val f: Int) {
2+
class Inner extends Outer(5) {
3+
def g(): Int = this.f
54
}
65
}
76

87
object O {
98
def foo(i: Outer): Unit =
109
val i2 = new i.Inner // i2.outer should always be OfClass(Outer)
11-
foo(i2)
10+
println("i2.g = " + i2.g())
1211

13-
foo(new Outer)
12+
foo(new Outer(6))
1413
}

tests/init-global/pos/multiple-outers.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,20 @@ class A(val x: Int) {
1111
}
1212
}
1313
}
14-
class AA(x: Int) extends A(x) {
14+
class AA(y: Int) extends A(y+1) {
15+
class E {}
1516
def foo = {
1617
val a = if true then new A(42) else new AA(46)
1718
println("a = " + a.hashCode())
1819
class C /*outer: AA(44) (`Main.aa`)*/ extends a.B /*outer: A(42) or AA(46) (`a`)*/ {
1920
println("AA.this = " + AA.this.hashCode()) // Main.aa
2021
println("AA.this.x = " + x) // C --> outer AA --> parent A (44)
2122
override def fooz2 = x // 44
23+
val z = fooz // (A.this.x)
24+
println("z = " + z)
25+
2226
}
27+
class B extends AA.this.E {}
2328
val c: C = new C
2429
println("c = " + c.hashCode())
2530
val d = new c.D // outer: C (`c`)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class A {
2+
val field_a = 5
3+
def bar(): Int = A.this.field_a
4+
}
5+
6+
class B extends A {
7+
val field_b = field_a
8+
class C {
9+
def bar2() = B.this.field_b
10+
val field_c = bar() // expands to B.this.bar()
11+
val field_c2 = field_a // C --> outer B --> parent A
12+
}
13+
}
14+
15+
object O:
16+
val b = new B
17+
class D extends b.C { // D --> parent C --> outer B
18+
val field_d = bar2()
19+
}
20+
val d = new D

tests/init-global/warn/global-cycle6.check

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@
88
| │ ^
99
| ├── object B { [ global-cycle6.scala:8 ]
1010
| │ ^
11-
| └── val a = new A.Inner [ global-cycle6.scala:9 ]
12-
| ^^^^^^^^^^^
11+
| ├── val a = new A.Inner [ global-cycle6.scala:9 ]
12+
| │ ^^^^^^^^^^^
13+
| ├── class Inner { [ global-cycle6.scala:3 ]
14+
| │ ^
15+
| └── println(n) // warn [ global-cycle6.scala:4 ]
16+
| ^
1317
-- Warning: tests/init-global/warn/global-cycle6.scala:4:12 ------------------------------------------------------------
1418
4 | println(n) // warn
1519
| ^
@@ -22,15 +26,3 @@
2226
| │ ^
2327
| └── println(n) // warn [ global-cycle6.scala:4 ]
2428
| ^
25-
-- Warning: tests/init-global/warn/global-cycle6.scala:14:9 ------------------------------------------------------------
26-
14 | object A { // warn
27-
| ^
28-
| Cyclic initialization: object A -> object B -> object A. Calling trace:
29-
| ├── object A { // warn [ global-cycle6.scala:14 ]
30-
| │ ^
31-
| ├── val n: Int = B.m [ global-cycle6.scala:15 ]
32-
| │ ^
33-
| ├── object B { [ global-cycle6.scala:21 ]
34-
| │ ^
35-
| └── val a = new A.Inner [ global-cycle6.scala:22 ]
36-
| ^^^^^^^^^^^

tests/init-global/warn/global-cycle6.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ object B {
1111
}
1212

1313
object O {
14-
object A { // warn
14+
object A {
1515
val n: Int = B.m
1616
class Inner {
1717
val x: Int = 4
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-- Warning: tests/init-global/warn/inner-extends-outer.scala:22:19 -----------------------------------------------------
2+
22 | def bar(): Int = f2 // warn
3+
| ^^
4+
| Access uninitialized field value f2. Calling trace:
5+
| ├── object O extends T { [ inner-extends-outer.scala:15 ]
6+
| │ ^
7+
| ├── val f1 = foo(new Outer(this)) [ inner-extends-outer.scala:20 ]
8+
| │ ^^^^^^^^^^^^^^^^^^^^
9+
| ├── def foo(i: Outer): Int = [ inner-extends-outer.scala:16 ]
10+
| │ ^
11+
| ├── i2.g() [ inner-extends-outer.scala:18 ]
12+
| │ ^^^^^^
13+
| ├── def g(): Int = Outer.this.t.bar() [ inner-extends-outer.scala:11 ]
14+
| │ ^^^^^^^^^^^^^^^^^^
15+
| └── def bar(): Int = f2 // warn [ inner-extends-outer.scala:22 ]
16+
| ^^
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
trait T {
2+
def bar(): Int
3+
}
4+
5+
class C extends T {
6+
def bar(): Int = 5
7+
}
8+
9+
class Outer(val t: T) {
10+
class Inner extends Outer(new C) {
11+
def g(): Int = Outer.this.t.bar()
12+
}
13+
}
14+
15+
object O extends T {
16+
def foo(i: Outer): Int =
17+
val i2 = new i.Inner // i2.outer should always be OfClass(Outer)
18+
i2.g()
19+
20+
val f1 = foo(new Outer(this))
21+
val f2 = 5
22+
def bar(): Int = f2 // warn
23+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-- Warning: tests/init-global/warn/resolve-outer-of-parent.scala:7:16 --------------------------------------------------
2+
7 | def foo() = O.d // warn
3+
| ^^^
4+
| Access uninitialized field value d. Calling trace:
5+
| ├── object O: [ resolve-outer-of-parent.scala:14 ]
6+
| │ ^
7+
| ├── val d = new D [ resolve-outer-of-parent.scala:19 ]
8+
| │ ^^^^^
9+
| ├── class D extends b.C { // D --> parent C --> outer B [ resolve-outer-of-parent.scala:16 ]
10+
| │ ^
11+
| ├── val field_d = bar2() [ resolve-outer-of-parent.scala:17 ]
12+
| │ ^^^^^^
13+
| ├── def bar2() = B.this.foo() [ resolve-outer-of-parent.scala:9 ]
14+
| │ ^^^^^^^^^^^^
15+
| └── def foo() = O.d // warn [ resolve-outer-of-parent.scala:7 ]
16+
| ^^^
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class A {
2+
val field_a = 5
3+
def bar(): Int = A.this.field_a
4+
}
5+
6+
class B extends A {
7+
def foo() = O.d // warn
8+
class C {
9+
def bar2() = B.this.foo()
10+
val field_c = bar() // expands to B.this.bar()
11+
}
12+
}
13+
14+
object O:
15+
val b = new B
16+
class D extends b.C { // D --> parent C --> outer B
17+
val field_d = bar2()
18+
}
19+
val d = new D

0 commit comments

Comments
 (0)