Skip to content

Commit d3b4e26

Browse files
committed
Add definition of Errors
1 parent fa03025 commit d3b4e26

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package dotty.tools.dotc
2+
package transform
3+
package init
4+
5+
import ast.tpd._
6+
7+
import core._
8+
import Decorators._
9+
import Types._, Symbols._, Contexts._
10+
11+
import Effects._, Potentials._
12+
13+
object Errors {
14+
type Errors = Set[Error]
15+
val empty: Errors = Set.empty
16+
17+
sealed trait Error {
18+
def trace: Vector[Tree]
19+
def report(implicit ctx: Context): Unit
20+
21+
def stacktrace(implicit ctx: Context): String = {
22+
var indentCount = 0
23+
var last = ""
24+
val sb = new StringBuilder
25+
trace.foreach { tree =>
26+
indentCount += 1
27+
val pos = tree.sourcePos
28+
val line = "[ " + pos.source.file.name + ":" + (pos.line + 1) + " ]"
29+
if (last != line)
30+
sb.append(
31+
if (pos.source.exists)
32+
i"${ " " * indentCount }-> ${pos.lineContent.trim}\t$line\n"
33+
else
34+
i"${tree.show}\n"
35+
)
36+
last = line
37+
}
38+
sb.toString
39+
}
40+
}
41+
42+
/** Access non-initialized field */
43+
case class AccessNonInit(field: Symbol, trace: Vector[Tree]) extends Error {
44+
def report(implicit ctx: Context): Unit = ???
45+
}
46+
47+
/** Promote `this` under initialization to fully-initialized */
48+
case class PromoteThis(pot: ThisRef, trace: Vector[Tree]) extends Error {
49+
def report(implicit ctx: Context): Unit = ???
50+
}
51+
52+
/** Promote a cold value under initialization to fully-initialized */
53+
case class PromoteCold(trace: Vector[Tree]) extends Error {
54+
def report(implicit ctx: Context): Unit = ???
55+
}
56+
57+
/** Promote a value under initialization to fully-initialized */
58+
case class UnsafePromotion(pot: Potential, trace: Vector[Tree], errors: Set[Error]) extends Error {
59+
def report(implicit ctx: Context): Unit = ???
60+
}
61+
}

0 commit comments

Comments
 (0)