Skip to content

Commit 11d46bc

Browse files
committed
Fix owner of values with static flag
With the flag <static>, the enclosing class will be skipped. See the documentation `SymDenotation.enclosingClass`
1 parent ff2455a commit 11d46bc

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ object Errors {
6969

7070
/** Promote `this` under initialization to fully-initialized */
7171
case class PromoteError(msg: String, source: Tree, trace: Seq[Tree]) extends Error {
72-
def show(using Context): String = "Promote the value under initialization to fully-initialized. " + msg
72+
def show(using Context): String = "Promote the value under initialization to fully-initialized. " + msg + "."
7373
}
7474

7575
case class AccessCold(field: Symbol, source: Tree, trace: Seq[Tree]) extends Error {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ class Semantic {
892892
case Hot => Hot
893893
case addr: Addr =>
894894
val obj = heap(addr)
895-
val outerCls = klass.owner.enclosingClass.asClass
895+
val outerCls = klass.owner.lexicallyEnclosingClass.asClass
896896
if !obj.outers.contains(klass) then
897897
val error = PromoteError("outer not yet initialized, target = " + target + ", klass = " + klass, source, trace.toVector)
898898
report.error(error.show + error.stacktrace, source)

tests/init/neg/promotion-loop.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
|
66
|The unsafe promotion may cause the following problem(s):
77
|
8-
|1. Promote the value under initialization to fully-initialized. May only use initialized value as arguments Calling trace:
8+
|1. Promote the value under initialization to fully-initialized. May only use initialized value as arguments. Calling trace:
99
| -> val outer = test [ promotion-loop.scala:12 ]

tests/init/pos/enums.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
enum Color(val x: Int) {
2+
case Green extends Color(3)
3+
// case Red extends Color(2)
4+
case Violet extends Color(Green.x + 1)
5+
// case RGB(xx: Int) extends Color(xx)
6+
}

0 commit comments

Comments
 (0)