Skip to content

Commit 7671826

Browse files
committed
Better division of Error.show and Error.issue
1 parent 6bb7b5e commit 7671826

File tree

4 files changed

+25
-26
lines changed

4 files changed

+25
-26
lines changed

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

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ object Errors:
1919
def pos(using Context): SourcePosition = trace.last.sourcePos
2020

2121
def issue(using Context): Unit =
22-
report.warning(show + stacktrace(), this.pos)
22+
report.warning(show, this.pos)
2323

2424
def stacktrace(preamble: String = " Calling trace:\n")(using Context): String = if trace.isEmpty then "" else preamble + {
2525
var lastLineNum = -1
@@ -72,43 +72,37 @@ object Errors:
7272
case class AccessNonInit(field: Symbol, trace: Seq[Tree]) extends Error:
7373
def source: Tree = trace.last
7474
def show(using Context): String =
75-
"Access non-initialized " + field.show + "."
75+
"Access non-initialized " + field.show + "." + stacktrace()
7676

7777
override def pos(using Context): SourcePosition = field.sourcePos
7878

7979
/** Promote a value under initialization to fully-initialized */
8080
case class PromoteError(msg: String, trace: Seq[Tree]) extends Error:
81-
def show(using Context): String = msg
81+
def show(using Context): String = msg + stacktrace()
8282

8383
case class AccessCold(field: Symbol, trace: Seq[Tree]) extends Error:
8484
def show(using Context): String =
85-
"Access field on a value with an unknown initialization status."
85+
"Access field on a value with an unknown initialization status." + stacktrace()
8686

8787
case class CallCold(meth: Symbol, trace: Seq[Tree]) extends Error:
8888
def show(using Context): String =
89-
"Call method on a value with an unknown initialization" + "."
89+
"Call method on a value with an unknown initialization." + stacktrace()
9090

9191
case class CallUnknown(meth: Symbol, trace: Seq[Tree]) extends Error:
9292
def show(using Context): String =
9393
val prefix = if meth.is(Flags.Method) then "Calling the external method " else "Accessing the external field"
94-
prefix + meth.show + " may cause initialization errors" + "."
94+
prefix + meth.show + " may cause initialization errors." + stacktrace()
9595

9696
/** Promote a value under initialization to fully-initialized */
9797
case class UnsafePromotion(msg: String, trace: Seq[Tree], error: Error) extends Error:
98-
override def issue(using Context): Unit =
99-
report.warning(show, this.pos)
100-
10198
def show(using Context): String =
10299
msg + stacktrace() + "\n" +
103100
"Promoting the value to fully initialized failed due to the following problem:\n" +
104-
error.show + error.stacktrace()
101+
error.show
105102

106103
/** Unsafe leaking a non-hot value as constructor arguments */
107104
case class UnsafeLeaking(trace: Seq[Tree], error: Error) extends Error:
108-
override def issue(using Context): Unit =
109-
report.warning(show, this.pos)
110-
111105
def show(using Context): String =
112-
"Unsafe leaking of uninitialized value: the leaked value is used. " + stacktrace() + "\n" +
113-
"The leaked uninitialized value is used as follows:\n" +
114-
error.stacktrace(preamble = "")
106+
"Problematic object instantiation with uninitialized arguments." + stacktrace() + "\n" +
107+
"It leads to the following error during object initialization:\n" +
108+
error.show

tests/init/neg/cycle-structure.check

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
-- Error: tests/init/neg/cycle-structure.scala:9:13 --------------------------------------------------------------------
22
9 | val x = A(this) // error
33
| ^^^^^^^
4-
| Unsafe leaking of uninitialized value: the leaked value is used. Calling trace:
4+
| Problematic object instantiation with uninitialized arguments. Calling trace:
55
| -> case class B(a: A) { [ cycle-structure.scala:7 ]
66
| ^
77
| -> val x = A(this) // error [ cycle-structure.scala:9 ]
88
| ^^^^^^^
99
|
10-
| The leaked uninitialized value is used as follows:
10+
| It leads to the following error during object initialization:
11+
| Access field on a value with an unknown initialization status. Calling trace:
1112
| -> case class A(b: B) { [ cycle-structure.scala:1 ]
1213
| ^
1314
| -> val x1 = b.x [ cycle-structure.scala:2 ]
1415
| ^^^
1516
-- Error: tests/init/neg/cycle-structure.scala:3:13 --------------------------------------------------------------------
1617
3 | val x = B(this) // error
1718
| ^^^^^^^
18-
| Unsafe leaking of uninitialized value: the leaked value is used. Calling trace:
19+
| Problematic object instantiation with uninitialized arguments. Calling trace:
1920
| -> case class A(b: B) { [ cycle-structure.scala:1 ]
2021
| ^
2122
| -> val x = B(this) // error [ cycle-structure.scala:3 ]
2223
| ^^^^^^^
2324
|
24-
| The leaked uninitialized value is used as follows:
25+
| It leads to the following error during object initialization:
26+
| Access field on a value with an unknown initialization status. Calling trace:
2527
| -> case class B(a: A) { [ cycle-structure.scala:7 ]
2628
| ^
2729
| -> val x1 = a.x [ cycle-structure.scala:8 ]

tests/init/neg/i15363.check

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
-- Error: tests/init/neg/i15363.scala:3:10 -----------------------------------------------------------------------------
22
3 | val b = new B(this) // error
33
| ^^^^^^^^^^^
4-
| Unsafe leaking of uninitialized value: the leaked value is used. Calling trace:
4+
| Problematic object instantiation with uninitialized arguments. Calling trace:
55
| -> class A: [ i15363.scala:1 ]
66
| ^
77
| -> val b = new B(this) // error [ i15363.scala:3 ]
88
| ^^^^^^^^^^^
99
|
10-
| The leaked uninitialized value is used as follows:
10+
| It leads to the following error during object initialization:
11+
| Access field on a value with an unknown initialization status. Calling trace:
1112
| -> class B(a: A): [ i15363.scala:7 ]
1213
| ^
1314
| -> val x = a.m [ i15363.scala:8 ]

tests/init/neg/secondary-ctor4.check

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- Error: tests/init/neg/secondary-ctor4.scala:54:14 -------------------------------------------------------------------
22
54 | val c = new C(b, 5) // error
33
| ^^^^^^^^^^^
4-
| Unsafe leaking of uninitialized value: the leaked value is used. Calling trace:
4+
| Problematic object instantiation with uninitialized arguments. Calling trace:
55
| -> class N(d: D) extends M(d) { [ secondary-ctor4.scala:59 ]
66
| ^
77
| -> def this(d: D) = { [ secondary-ctor4.scala:7 ]
@@ -13,7 +13,8 @@
1313
| -> val c = new C(b, 5) // error [ secondary-ctor4.scala:54 ]
1414
| ^^^^^^^^^^^
1515
|
16-
| The leaked uninitialized value is used as follows:
16+
| It leads to the following error during object initialization:
17+
| Access field on a value with an unknown initialization status. Calling trace:
1718
| -> def this(b: B, x: Int) = this(b) [ secondary-ctor4.scala:49 ]
1819
| ^^^^^^^
1920
| -> class C(b: B) extends A(b) with T { [ secondary-ctor4.scala:48 ]
@@ -29,15 +30,16 @@
2930
-- Error: tests/init/neg/secondary-ctor4.scala:42:4 --------------------------------------------------------------------
3031
42 | new A(new B(new D)) // error
3132
| ^^^^^^^^^^^^^^^^^^^
32-
| Unsafe leaking of uninitialized value: the leaked value is used. Calling trace:
33+
| Problematic object instantiation with uninitialized arguments. Calling trace:
3334
| -> class N(d: D) extends M(d) { [ secondary-ctor4.scala:59 ]
3435
| ^
3536
| -> def this(d: D) = { [ secondary-ctor4.scala:7 ]
3637
| ^
3738
| -> new A(new B(new D)) // error [ secondary-ctor4.scala:42 ]
3839
| ^^^^^^^^^^^^^^^^^^^
3940
|
40-
| The leaked uninitialized value is used as follows:
41+
| It leads to the following error during object initialization:
42+
| Access field on a value with an unknown initialization status. Calling trace:
4143
| -> def this(b: B) = { [ secondary-ctor4.scala:17 ]
4244
| ^
4345
| -> Inner().foo() [ secondary-ctor4.scala:26 ]

0 commit comments

Comments
 (0)