Skip to content

Commit b40c459

Browse files
authored
Special case for next field of colon colon in global init checker (#20281)
This PR adds a special case to suppress a warning pertaining to the next field and colon colon operator. Added a test case that produces the warning when the hardcoded logic is not present.
2 parents 9348ae7 + c714ae5 commit b40c459

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,8 @@ class Objects(using Context @constructorOnly):
812812
else
813813
Bottom
814814
else if target.exists then
815-
if target.isOneOf(Flags.Mutable) then
815+
def isNextFieldOfColonColon: Boolean = ref.klass == defn.ConsClass && target.name.toString == "next"
816+
if target.isOneOf(Flags.Mutable) && !isNextFieldOfColonColon then
816817
if ref.hasVar(target) then
817818
val addr = ref.varAddr(target)
818819
if addr.owner == State.currentObject then
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
object A:
2+
val a: List[Int] = List(1, 2, 3)
3+
4+
object B:
5+
val b = A.a.size

0 commit comments

Comments
 (0)