File tree Expand file tree Collapse file tree 10 files changed +504
-244
lines changed
compiler/src/dotty/tools/dotc/transform/init Expand file tree Collapse file tree 10 files changed +504
-244
lines changed Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change 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
5
4
}
6
5
}
7
6
8
7
object O {
9
8
def foo (i : Outer ): Unit =
10
9
val i2 = new i.Inner // i2.outer should always be OfClass(Outer)
11
- foo(i2 )
10
+ println( " i2.g = " + i2.g() )
12
11
13
- foo(new Outer )
12
+ foo(new Outer ( 6 ) )
14
13
}
Original file line number Diff line number Diff line change @@ -11,15 +11,20 @@ class A(val x: Int) {
11
11
}
12
12
}
13
13
}
14
- class AA (x : Int ) extends A (x) {
14
+ class AA (y : Int ) extends A (y+ 1 ) {
15
+ class E {}
15
16
def foo = {
16
17
val a = if true then new A (42 ) else new AA (46 )
17
18
println(" a = " + a.hashCode())
18
19
class C /* outer: AA(44) (`Main.aa`)*/ extends a.B /* outer: A(42) or AA(46) (`a`)*/ {
19
20
println(" AA.this = " + AA .this .hashCode()) // Main.aa
20
21
println(" AA.this.x = " + x) // C --> outer AA --> parent A (44)
21
22
override def fooz2 = x // 44
23
+ val z = fooz // (A.this.x)
24
+ println(" z = " + z)
25
+
22
26
}
27
+ class B extends AA .this .E {}
23
28
val c : C = new C
24
29
println(" c = " + c.hashCode())
25
30
val d = new c.D // outer: C (`c`)
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change 8
8
| │ ^
9
9
| ├── object B { [ global-cycle6.scala:8 ]
10
10
| │ ^
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
+ | ^
13
17
-- Warning: tests/init-global/warn/global-cycle6.scala:4:12 ------------------------------------------------------------
14
18
4 | println(n) // warn
15
19
| ^
22
26
| │ ^
23
27
| └── println(n) // warn [ global-cycle6.scala:4 ]
24
28
| ^
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
- | ^^^^^^^^^^^
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ object B {
11
11
}
12
12
13
13
object O {
14
- object A { // warn
14
+ object A {
15
15
val n : Int = B .m
16
16
class Inner {
17
17
val x : Int = 4
Original file line number Diff line number Diff line change
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
+ | ^^
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ | ^^^
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments