Skip to content

Commit 2fe9717

Browse files
committed
More errors
1 parent d3b4e26 commit 2fe9717

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

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

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ object Errors {
1717
sealed trait Error {
1818
def trace: Vector[Tree]
1919
def report(implicit ctx: Context): Unit
20+
def message(implicit ctx: Context): String
2021

2122
def stacktrace(implicit ctx: Context): String = {
2223
var indentCount = 0
@@ -41,21 +42,55 @@ object Errors {
4142

4243
/** Access non-initialized field */
4344
case class AccessNonInit(field: Symbol, trace: Vector[Tree]) extends Error {
45+
def message(implicit ctx: Context): String =
46+
"Access non-initialized field " + field.show + ". Calling trace:\n" + stacktrace
47+
4448
def report(implicit ctx: Context): Unit = ???
4549
}
4650

4751
/** Promote `this` under initialization to fully-initialized */
48-
case class PromoteThis(pot: ThisRef, trace: Vector[Tree]) extends Error {
52+
case class PromoteThis(pot: ThisRef, source: Tree, trace: Vector[Tree]) extends Error {
53+
def message(implicit ctx: Context): String = "Promote `this` to be initialized while it is not. Calling trace:\n" + stacktrace
4954
def report(implicit ctx: Context): Unit = ???
5055
}
5156

5257
/** Promote a cold value under initialization to fully-initialized */
53-
case class PromoteCold(trace: Vector[Tree]) extends Error {
58+
case class PromoteCold(source: Tree, trace: Vector[Tree]) extends Error {
59+
def message(implicit ctx: Context): String =
60+
"Promoting the value " + source.show + " to be initialized while it is under initialization" +
61+
". Calling trace:\n" + stacktrace
62+
63+
def report(implicit ctx: Context): Unit = ???
64+
}
65+
66+
case class AccessCold(field: Symbol, source: Tree, trace: Vector[Tree]) extends Error {
67+
def message(implicit ctx: Context): String =
68+
"Access field " + source.show + " on a value under unknown initialization status" +
69+
". Calling trace:\n" + stacktrace
70+
71+
def report(implicit ctx: Context): Unit = ???
72+
}
73+
74+
case class CallCold(meth: Symbol, source: Tree, trace: Vector[Tree]) extends Error {
75+
def message(implicit ctx: Context): String =
76+
"Call method " + source.show + " on a value under unknown initialization" +
77+
". Calling trace:\n" + stacktrace
78+
79+
def report(implicit ctx: Context): Unit = ???
80+
}
81+
82+
case class CallUnknown(meth: Symbol, source: Tree, trace: Vector[Tree]) extends Error {
83+
def message(implicit ctx: Context): String =
84+
"Calling the external method " + meth.show +
85+
" may cause initialization errors" + ". Calling trace:\n" + stacktrace
86+
5487
def report(implicit ctx: Context): Unit = ???
5588
}
5689

5790
/** Promote a value under initialization to fully-initialized */
58-
case class UnsafePromotion(pot: Potential, trace: Vector[Tree], errors: Set[Error]) extends Error {
91+
case class UnsafePromotion(pot: Potential, source: Tree, trace: Vector[Tree], errors: Set[Error]) extends Error {
92+
def message(implicit ctx: Context): String = ???
93+
5994
def report(implicit ctx: Context): Unit = ???
6095
}
6196
}

0 commit comments

Comments
 (0)