@@ -13,6 +13,8 @@ import java.util.Optional
13
13
import scala .util .chaining ._
14
14
import core .Decorators .toMessage
15
15
16
+ import scala .annotation .constructorOnly
17
+
16
18
object Diagnostic :
17
19
18
20
def shouldExplain (dia : Diagnostic )(using Context ): Boolean =
@@ -24,8 +26,8 @@ object Diagnostic:
24
26
class Error (
25
27
msg : Message ,
26
28
pos : SourcePosition
27
- ) extends Diagnostic (msg, pos, ERROR ):
28
- def this (str : => String , pos : SourcePosition ) = this (str.toMessage, pos)
29
+ )( using @ constructorOnly ictx : Context ) extends Diagnostic (msg, pos, ERROR ):
30
+ def this (str : => String , pos : SourcePosition )( using Context ) = this (str.toMessage, pos)
29
31
30
32
/** A sticky error is an error that should not be hidden by backtracking and
31
33
* trying some alternative path. Typically, errors issued after catching
@@ -34,62 +36,68 @@ object Diagnostic:
34
36
class StickyError (
35
37
msg : Message ,
36
38
pos : SourcePosition
37
- ) extends Error (msg, pos)
39
+ )( using @ constructorOnly ictx : Context ) extends Error (msg, pos)
38
40
39
41
class Warning (
40
42
msg : Message ,
41
43
pos : SourcePosition
42
- ) extends Diagnostic (msg, pos, WARNING ) {
43
- def toError : Error = new Error (msg, pos).tap(e => if isVerbose then e.setVerbose())
44
- def toInfo : Info = new Info (msg, pos).tap(e => if isVerbose then e.setVerbose())
44
+ )( using @ constructorOnly ictx : Context ) extends Diagnostic (msg, pos, WARNING ) {
45
+ def toError ( using Context ) : Error = new Error (msg, pos).tap(e => if isVerbose then e.setVerbose())
46
+ def toInfo ( using Context ) : Info = new Info (msg, pos).tap(e => if isVerbose then e.setVerbose())
45
47
def isSummarizedConditional (using Context ): Boolean = false
46
48
}
47
49
48
50
class Info (
49
51
msg : Message ,
50
52
pos : SourcePosition
51
- ) extends Diagnostic (msg, pos, INFO ):
52
- def this (str : => String , pos : SourcePosition ) = this (str.toMessage, pos)
53
+ )( using @ constructorOnly ictx : Context ) extends Diagnostic (msg, pos, INFO ):
54
+ def this (str : => String , pos : SourcePosition )( using Context ) = this (str.toMessage, pos)
53
55
54
56
abstract class ConditionalWarning (
55
57
msg : Message ,
56
58
pos : SourcePosition
57
- ) extends Warning (msg, pos) {
59
+ )( using @ constructorOnly ictx : Context ) extends Warning (msg, pos) {
58
60
def enablingOption (using Context ): Setting [Boolean ]
59
61
override def isSummarizedConditional (using Context ): Boolean = ! enablingOption.value
60
62
}
61
63
62
64
class FeatureWarning (
63
65
msg : Message ,
64
66
pos : SourcePosition
65
- ) extends ConditionalWarning (msg, pos) {
67
+ )( using @ constructorOnly ictx : Context ) extends ConditionalWarning (msg, pos) {
66
68
def enablingOption (using Context ): Setting [Boolean ] = ctx.settings.feature
67
69
}
68
70
69
71
class UncheckedWarning (
70
72
msg : Message ,
71
73
pos : SourcePosition
72
- ) extends ConditionalWarning (msg, pos) {
74
+ )( using @ constructorOnly ictx : Context ) extends ConditionalWarning (msg, pos) {
73
75
def enablingOption (using Context ): Setting [Boolean ] = ctx.settings.unchecked
74
76
}
75
77
76
78
class DeprecationWarning (
77
79
msg : Message ,
78
80
pos : SourcePosition
79
- ) extends ConditionalWarning (msg, pos) {
81
+ )( using @ constructorOnly ictx : Context ) extends ConditionalWarning (msg, pos) {
80
82
def enablingOption (using Context ): Setting [Boolean ] = ctx.settings.deprecation
81
83
}
82
84
83
85
class MigrationWarning (
84
86
msg : Message ,
85
87
pos : SourcePosition
86
- ) extends Warning (msg, pos)
88
+ )( using @ constructorOnly ictx : Context ) extends Warning (msg, pos)
87
89
88
90
class Diagnostic (
89
91
val msg : Message ,
90
92
val pos : SourcePosition ,
91
93
val level : Int
92
- ) extends Exception with interfaces.Diagnostic :
94
+ )(using @ constructorOnly ictx : Context ) extends Exception (
95
+ // These are just the default values
96
+ /* message =*/ null , /* cause =*/ null , /* enableSuppression =*/ true ,
97
+
98
+ // Performance optimization: don't compute the stack trace unless requested by the reporter.
99
+ /* writableStackTrace =*/ ictx.reporter.computeStackTraces
100
+ ) with interfaces.Diagnostic :
93
101
private var verbose : Boolean = false
94
102
def isVerbose : Boolean = verbose
95
103
def setVerbose (): this .type =
0 commit comments