-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15703 from dotty-staging/init-super-accessor
Handle super accessors in initialization checker
- Loading branch information
Showing
5 changed files
with
113 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
-- Error: tests/init/neg/super-resolution.scala:21:6 ------------------------------------------------------------------- | ||
21 | val m = 30 // error | ||
| ^ | ||
| Access non-initialized value m. Calling trace: | ||
| -> class C extends A with M with N: [ super-resolution.scala:17 ] | ||
| ^ | ||
| -> foo() [ super-resolution.scala:18 ] | ||
| ^^^^^ | ||
| -> override def foo(): Int = b * super.foo() [ super-resolution.scala:15 ] | ||
| ^^^^^^^^^^^ | ||
| -> override def foo(): Int = a + super.foo() [ super-resolution.scala:11 ] | ||
| ^^^^^^^^^^^ | ||
| -> def foo(): Int = m [ super-resolution.scala:7 ] | ||
| ^ | ||
-- Error: tests/init/neg/super-resolution.scala:19:6 ------------------------------------------------------------------- | ||
19 | val a = 10 // error | ||
| ^ | ||
| Access non-initialized value a. Calling trace: | ||
| -> class C extends A with M with N: [ super-resolution.scala:17 ] | ||
| ^ | ||
| -> foo() [ super-resolution.scala:18 ] | ||
| ^^^^^ | ||
| -> override def foo(): Int = b * super.foo() [ super-resolution.scala:15 ] | ||
| ^^^^^^^^^^^ | ||
| -> override def foo(): Int = a + super.foo() [ super-resolution.scala:11 ] | ||
| ^ | ||
-- Error: tests/init/neg/super-resolution.scala:20:6 ------------------------------------------------------------------- | ||
20 | val b = 20 // error | ||
| ^ | ||
| Access non-initialized value b. Calling trace: | ||
| -> class C extends A with M with N: [ super-resolution.scala:17 ] | ||
| ^ | ||
| -> foo() [ super-resolution.scala:18 ] | ||
| ^^^^^ | ||
| -> override def foo(): Int = b * super.foo() [ super-resolution.scala:15 ] | ||
| ^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
abstract class A: | ||
val n: Int | ||
def foo(): Int = n | ||
|
||
trait B: | ||
val m: Int | ||
def foo(): Int = m | ||
|
||
trait M extends A with B: | ||
val a: Int | ||
override def foo(): Int = a + super.foo() | ||
|
||
trait N extends A with B: | ||
val b: Int | ||
override def foo(): Int = b * super.foo() | ||
|
||
class C extends A with M with N: | ||
foo() | ||
val a = 10 // error | ||
val b = 20 // error | ||
val m = 30 // error | ||
val n = 40 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
-- Error: tests/init/neg/super-resolution2.scala:19:6 ------------------------------------------------------------------ | ||
19 | val n = 40 // error | ||
| ^ | ||
| Access non-initialized value n. Calling trace: | ||
| -> class N extends A with B: [ super-resolution2.scala:9 ] | ||
| ^ | ||
| -> new Inner [ super-resolution2.scala:16 ] | ||
| ^^^^^^^^^ | ||
| -> class Inner: [ super-resolution2.scala:12 ] | ||
| ^ | ||
| -> N.super[A].foo() [ super-resolution2.scala:13 ] | ||
| ^^^^^^^^^^^^^^^^ | ||
| -> def foo(): Int = n [ super-resolution2.scala:3 ] | ||
| ^ | ||
-- Error: tests/init/neg/super-resolution2.scala:18:6 ------------------------------------------------------------------ | ||
18 | val m = 30 // error | ||
| ^ | ||
| Access non-initialized value m. Calling trace: | ||
| -> class N extends A with B: [ super-resolution2.scala:9 ] | ||
| ^ | ||
| -> new Inner [ super-resolution2.scala:16 ] | ||
| ^^^^^^^^^ | ||
| -> class Inner: [ super-resolution2.scala:12 ] | ||
| ^ | ||
| -> N.super.foo() [ super-resolution2.scala:14 ] | ||
| ^^^^^^^^^^^^^ | ||
| -> def foo(): Int = m [ super-resolution2.scala:7 ] | ||
| ^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
abstract class A: | ||
val n: Int | ||
def foo(): Int = n | ||
|
||
trait B: | ||
val m: Int | ||
def foo(): Int = m | ||
|
||
class N extends A with B: | ||
override def foo(): Int = a * super.foo() | ||
|
||
class Inner: | ||
N.super[A].foo() | ||
N.super.foo() | ||
|
||
new Inner | ||
|
||
val m = 30 // error | ||
val n = 40 // error | ||
val a = 50 |