@@ -12,7 +12,7 @@ import Types._, Symbols._, Contexts._
12
12
import scala .collection .mutable
13
13
14
14
object Errors :
15
- sealed trait Error {
15
+ sealed trait Error :
16
16
def trace : Seq [Tree ]
17
17
def show (using Context ): String
18
18
@@ -55,7 +55,7 @@ object Errors:
55
55
/** Used to underline source positions in the stack trace
56
56
* pos.source must exist
57
57
*/
58
- private def positionMarker (pos : SourcePosition ): String = {
58
+ private def positionMarker (pos : SourcePosition ): String =
59
59
val trimmed = pos.lineContent.takeWhile(c => c.isWhitespace).length
60
60
val padding = pos.startColumnPadding.substring(trimmed).nn + " "
61
61
val carets =
@@ -64,48 +64,41 @@ object Errors:
64
64
else " ^"
65
65
66
66
s " $padding$carets\n "
67
- }
68
67
69
68
override def toString () = this .getClass.getName.nn
70
- }
69
+ end Error
71
70
72
71
/** Access non-initialized field */
73
- case class AccessNonInit (field : Symbol , trace : Seq [Tree ]) extends Error {
72
+ case class AccessNonInit (field : Symbol , trace : Seq [Tree ]) extends Error :
74
73
def source : Tree = trace.last
75
74
def show (using Context ): String =
76
75
" Access non-initialized " + field.show + " ."
77
76
78
77
override def pos (using Context ): SourcePosition = field.sourcePos
79
- }
80
78
81
79
/** Promote a value under initialization to fully-initialized */
82
- case class PromoteError (msg : String , trace : Seq [Tree ]) extends Error {
80
+ case class PromoteError (msg : String , trace : Seq [Tree ]) extends Error :
83
81
def show (using Context ): String = msg
84
- }
85
82
86
- case class AccessCold (field : Symbol , trace : Seq [Tree ]) extends Error {
83
+ case class AccessCold (field : Symbol , trace : Seq [Tree ]) extends Error :
87
84
def show (using Context ): String =
88
85
" Access field on a value with an unknown initialization status."
89
- }
90
86
91
- case class CallCold (meth : Symbol , trace : Seq [Tree ]) extends Error {
87
+ case class CallCold (meth : Symbol , trace : Seq [Tree ]) extends Error :
92
88
def show (using Context ): String =
93
89
" Call method on a value with an unknown initialization" + " ."
94
- }
95
90
96
- case class CallUnknown (meth : Symbol , trace : Seq [Tree ]) extends Error {
91
+ case class CallUnknown (meth : Symbol , trace : Seq [Tree ]) extends Error :
97
92
def show (using Context ): String =
98
93
val prefix = if meth.is(Flags .Method ) then " Calling the external method " else " Accessing the external field"
99
94
prefix + meth.show + " may cause initialization errors" + " ."
100
- }
101
95
102
96
/** Promote a value under initialization to fully-initialized */
103
- case class UnsafePromotion (msg : String , trace : Seq [Tree ], error : Error ) extends Error {
97
+ case class UnsafePromotion (msg : String , trace : Seq [Tree ], error : Error ) extends Error :
104
98
override def issue (using Context ): Unit =
105
99
report.warning(show, this .pos)
106
100
107
101
def show (using Context ): String =
108
102
msg + stacktrace + " \n " +
109
103
" Promoting the value to fully initialized failed due to the following problem:\n " +
110
104
error.show + error.stacktrace
111
- }
0 commit comments