Skip to content

Commit fd6aaf7

Browse files
author
EnzeXing
committed
Only showing traces with >1 entries
1 parent db0cdb1 commit fd6aaf7

20 files changed

+20
-33
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,24 +1759,31 @@ class Objects:
17591759
if cls.isAllOf(Flags.JavaInterface) then Bottom
17601760
else evalType(tref.prefix, thisV, klass, elideObjectAccess = cls.isStatic)
17611761

1762+
def printTraceWhenMultiple(trace: Trace)(using Context): String =
1763+
if trace.toVector.size > 1 then
1764+
Trace.buildStacktrace(trace, "The mutable state is created through: " + System.lineSeparator())
1765+
else ""
1766+
17621767
val mutateErrorSet: mutable.Set[(ClassSymbol, ClassSymbol)] = mutable.Set.empty
17631768
def errorMutateOtherStaticObject(currentObj: ClassSymbol, addr: Heap.Addr)(using Trace, Context) =
17641769
val otherObj = addr.owner
1770+
val addr_trace = addr.getTrace
17651771
if mutateErrorSet.add((currentObj, otherObj)) then
17661772
val msg =
17671773
s"Mutating ${otherObj.show} during initialization of ${currentObj.show}.\n" +
17681774
"Mutating other static objects during the initialization of one static object is forbidden. " + Trace.show +
1769-
"The mutable state is created through: " + Trace.show(using addr.getTrace)
1775+
printTraceWhenMultiple(addr_trace)
17701776

17711777
report.warning(msg, Trace.position)
17721778

17731779
val readErrorSet: mutable.Set[(ClassSymbol, ClassSymbol)] = mutable.Set.empty
17741780
def errorReadOtherStaticObject(currentObj: ClassSymbol, addr: Heap.Addr)(using Trace, Context) =
17751781
val otherObj = addr.owner
1782+
val addr_trace = addr.getTrace
17761783
if readErrorSet.add((currentObj, otherObj)) then
17771784
val msg =
17781785
"Reading mutable state of " + otherObj.show + " during initialization of " + currentObj.show + ".\n" +
17791786
"Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. " + Trace.show +
1780-
"The mutable state is created through: " + Trace.show(using addr.getTrace)
1787+
printTraceWhenMultiple(addr_trace)
17811788

17821789
report.warning(msg, Trace.position)

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,3 @@
77
|│ ^
88
|└── val b: Int = A.a.foo() // warn [ global-cycle5.scala:10 ]
99
| ^^^
10-
|The mutable state is created through: Calling trace:
11-
|└── object A { [ global-cycle5.scala:5 ]
12-
| ^

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,3 @@
77
|│ ^
88
|└── var y = A.x * 2 // warn [ global-irrelevance1.scala:5 ]
99
| ^^^
10-
|The mutable state is created through: Calling trace:
11-
|└── object A: [ global-irrelevance1.scala:1 ]
12-
| ^

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,3 @@
1111
| │ ^
1212
| └── A.x = b * 2 // warn [ global-irrelevance2.scala:5 ]
1313
| ^^^^^^^^^^^^
14-
| The mutable state is created through: Calling trace:
15-
| └── object A: [ global-irrelevance2.scala:1 ]
16-
| ^

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@
99
|│ ^^^^^^^
1010
|└── (() => x) // warn [ global-irrelevance3.scala:9 ]
1111
| ^
12-
|The mutable state is created through:

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@
99
| │ ^^^^^^^^^
1010
| └── (y => x = y), // warn [ global-irrelevance4.scala:8 ]
1111
| ^^^^^^^^^^
12-
| The mutable state is created through:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
|│ ^
88
|└── var y = A.array(0) * 2 // warn [ global-irrelevance5.scala:6 ]
99
| ^^^^^^^^^^
10-
|The mutable state is created through: Calling trace:
10+
|The mutable state is created through:
1111
|├── object A: [ global-irrelevance5.scala:1 ]
1212
|│ ^
1313
|└── val array: Array[Int] = new Array(1) [ global-irrelevance5.scala:2 ]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
|│ ^
88
|└── var y = A.array(0).foo() * 2 // warn [ global-irrelevance6.scala:9 ]
99
| ^^^^^^^^^^
10-
|The mutable state is created through: Calling trace:
10+
|The mutable state is created through:
1111
|├── object A: [ global-irrelevance6.scala:4 ]
1212
|│ ^
1313
|└── val array: Array[Box] = new Array(1) [ global-irrelevance6.scala:5 ]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
|│ ^
88
|└── var y = A.array(0).foo() * 2 // warn [ global-irrelevance7.scala:10 ]
99
| ^^^^^^^^^^
10-
|The mutable state is created through: Calling trace:
10+
|The mutable state is created through:
1111
|├── object A: [ global-irrelevance7.scala:4 ]
1212
|│ ^
1313
|└── val array: Array[Box] = new Array(1) [ global-irrelevance7.scala:5 ]

tests/init-global/warn/mutable-array.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
|│ ^
88
|└── val x: Int = box.value // warn [ mutable-array.scala:8 ]
99
| ^^^^^^^^^
10-
|The mutable state is created through: Calling trace:
10+
|The mutable state is created through:
1111
|├── object A: [ mutable-array.scala:1 ]
1212
|│ ^
1313
|├── val box: Box = new Box(0) [ mutable-array.scala:3 ]

tests/init-global/warn/mutable-read1.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
|│ ^
88
|└── val n: Int = boxA.value // warn [ mutable-read1.scala:10 ]
99
| ^^^^^^^^^^
10-
|The mutable state is created through: Calling trace:
10+
|The mutable state is created through:
1111
|├── object A: [ mutable-read1.scala:3 ]
1212
|│ ^
1313
|├── val box: Box = new Box(4) [ mutable-read1.scala:4 ]

tests/init-global/warn/mutable-read2.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
|│ ^
88
|└── val b: Int = box.value // warn [ mutable-read2.scala:10 ]
99
| ^^^^^^^^^
10-
|The mutable state is created through: Calling trace:
10+
|The mutable state is created through:
1111
|├── object A: [ mutable-read2.scala:1 ]
1212
|│ ^
1313
|├── val box: Box = new Box(0) [ mutable-read2.scala:5 ]

tests/init-global/warn/mutable-read3.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
|│ ^
88
|└── val x: Int = box.value // warn [ mutable-read3.scala:9 ]
99
| ^^^^^^^^^
10-
|The mutable state is created through: Calling trace:
10+
|The mutable state is created through:
1111
|├── object A: [ mutable-read3.scala:1 ]
1212
|│ ^
1313
|├── val box: Box = new Box(0) [ mutable-read3.scala:3 ]

tests/init-global/warn/mutable-read4.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
|│ ^
88
|└── val n: Int = boxA.value // warn [ mutable-read4.scala:10 ]
99
| ^^^^^^^^^^
10-
|The mutable state is created through: Calling trace:
10+
|The mutable state is created through:
1111
|├── object A: [ mutable-read4.scala:3 ]
1212
|│ ^
1313
|├── val box: Box = new Box(4) [ mutable-read4.scala:4 ]

tests/init-global/warn/mutable-read5.check

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,3 @@
99
|│ ^^^^^^^^^^^^^^^^^^^^
1010
|└── def name(s: String): Name = Name(0, chrs.length) // warn [ mutable-read5.scala:4 ]
1111
| ^^^^
12-
|The mutable state is created through: Calling trace:
13-
|└── object Names: [ mutable-read5.scala:1 ]
14-
| ^

tests/init-global/warn/mutable-read6.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
|│ ^^^^^^^^^^^^^^^^
1010
|└── final def source: SourceFile = _source // warn [ mutable-read6.scala:7 ]
1111
| ^^^^^^^
12-
|The mutable state is created through: Calling trace:
12+
|The mutable state is created through:
1313
|├── object Contexts: [ mutable-read6.scala:3 ]
1414
|│ ^
1515
|├── val NoContext: Context = new Context [ mutable-read6.scala:4 ]

tests/init-global/warn/mutable-read7.check

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,3 @@
1313
|│ ^
1414
|└── if (Positioned.debug) { // warn [ mutable-read7.scala:7 ]
1515
| ^^^^^^^^^^^^^^^^
16-
|The mutable state is created through: Calling trace:
17-
|└── object Positioned: [ mutable-read7.scala:1 ]
18-
| ^

tests/init-global/warn/mutable-read8.check

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,3 @@
1111
|│ ^
1212
|└── if (Stats.monitored) println("record stats") // warn [ mutable-read8.scala:6 ]
1313
| ^^^^^^^^^^^^^^^
14-
|The mutable state is created through: Calling trace:
15-
|└── object Stats { [ mutable-read8.scala:1 ]
16-
| ^

tests/init-global/warn/patmat-unapplySeq.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
|│ ^^^^
1010
|└── def apply(i: Int): Box = array(i) // warn [ patmat-unapplySeq.scala:8 ]
1111
| ^^^^^^^^
12-
|The mutable state is created through: Calling trace:
12+
|The mutable state is created through:
1313
|├── object A: [ patmat-unapplySeq.scala:1 ]
1414
|│ ^
1515
|└── val array: Array[Box] = new Array(1) [ patmat-unapplySeq.scala:4 ]

tests/init-global/warn/patmat-unapplySeq2.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
|│ ^^^^^
1010
|└── def apply(i: Int): Box = array(i) // warn [ patmat-unapplySeq2.scala:8 ]
1111
| ^^^^^^^^
12-
|The mutable state is created through: Calling trace:
12+
|The mutable state is created through:
1313
|├── object A: [ patmat-unapplySeq2.scala:1 ]
1414
|│ ^
1515
|└── val array: Array[Box] = new Array(1) [ patmat-unapplySeq2.scala:4 ]

0 commit comments

Comments
 (0)