Skip to content

Commit edf760c

Browse files
author
EnzeXing
committed
Only conduct check on objects with source
1 parent af62be6 commit edf760c

File tree

5 files changed

+21
-18
lines changed

5 files changed

+21
-18
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1460,7 +1460,9 @@ class Objects(using Context @constructorOnly):
14601460
if classSym.hasSource then
14611461
State.checkObjectAccess(classSym)
14621462
else
1463-
ObjectRef(classSym)
1463+
val obj = ObjectRef(classSym)
1464+
obj.setAfterSuperCall()
1465+
obj
14641466
}
14651467

14661468

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
abstract class Foo[T](defaultValue: => T, arg1: Int = 1, arg2: Int = 2):
2-
def getValue: T = defaultValue
1+
class C(i: Int = 42, j: Int = 27) {
2+
val f = X.foo() // warn
3+
}
34

4-
enum Baz:
5-
case E1, E2 // warn
5+
object X extends C(j = 5):
6+
def foo() = 5
67

7-
object Baz extends Foo[Baz](Baz.E1, arg2 = 2) // warn
8-
9-
@main def test = println(Baz.getValue)
8+
@main def test = println:
9+
X

tests/init-global/warn/call-before-super4.scala

Lines changed: 0 additions & 9 deletions
This file was deleted.

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,13 @@
1818
| │ ^
1919
| └── val m: Int = A.n // warn [ global-cycle7.scala:6 ]
2020
| ^^^
21+
-- Warning: /Users/enzexing/IdeaProjects/dotty-staging/dotty/tests/init-global/warn/global-cycle7.scala:12:66
22+
12 | val tokenString, debugString: Array[String] = new Array[String](maxToken + 1)
23+
| ^^^^^^^^
24+
|Calling method maxToken of object module class JavaTokens$ before the super constructor of the object finishes! Calling trace:
25+
|├── object JavaTokens extends TokensCommon { [ global-cycle7.scala:15 ]
26+
|│ ^
27+
|├── abstract class TokensCommon { [ global-cycle7.scala:9 ]
28+
|│ ^
29+
|└── val tokenString, debugString: Array[String] = new Array[String](maxToken + 1) [ global-cycle7.scala:12 ]
30+
| ^^^^^^^^

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ object B {
99
abstract class TokensCommon {
1010
def maxToken: Int
1111

12-
val tokenString, debugString: Array[String] = new Array[String](maxToken + 1)
12+
val tokenString, debugString: Array[String] = new Array[String](maxToken + 1) // warn
1313
}
1414

1515
object JavaTokens extends TokensCommon {

0 commit comments

Comments
 (0)