@@ -3,54 +3,92 @@ package dotc
3
3
package reporting
4
4
package diagnostic
5
5
6
- import util .{ SourcePosition , NoSourcePosition }
6
+ import util .SourcePosition
7
7
import core .Contexts .Context
8
8
9
9
object Message {
10
+ /** This implicit conversion provides a fallback for error messages that have
11
+ * not yet been ported to the new scheme. Comment out this `implicit def` to
12
+ * see where old errors still exist
13
+ */
10
14
implicit def toNoExplanation (str : String ): Message =
11
15
new NoExplanation (str)
12
16
}
13
17
14
18
abstract class Message (val errorId : String ) { self =>
15
19
import messages ._
16
20
21
+ /** The `msg` contains the diagnostic message e.g:
22
+ *
23
+ * > expected: String
24
+ * > found: Int
25
+ *
26
+ * This message wil be placed underneath the position given by the enclosing
27
+ * `MessageContainer`
28
+ */
17
29
def msg : String
30
+
31
+ /** The kind of the error message is something like "Syntax" or "Type
32
+ * Mismatch"
33
+ */
18
34
def kind : String
35
+
36
+ /** The explanation should provide a detailed description of why the error
37
+ * occurred and use examples from the user's own code to illustrate how to
38
+ * avoid these errors.
39
+ */
19
40
def explanation : String
20
41
42
+ /** It is possible to map `msg` to add details, this is at the loss of
43
+ * precision since the type of the resulting `Message` won't be original
44
+ * extending class
45
+ *
46
+ * @return a `Message` with the mapped message
47
+ */
21
48
def mapMsg (f : String => String ) = new Message (errorId) {
22
49
val msg = f(self.msg)
23
50
val kind = self.kind
24
51
val explanation = self.explanation
25
52
}
26
53
54
+ /** Enclose this message in an `Error` container */
27
55
def error (pos : SourcePosition ) =
28
56
new Error (self, pos, explanation)
29
57
58
+ /** Enclose this message in an `Warning` container */
30
59
def warning (pos : SourcePosition ) =
31
60
new Warning (self, pos, explanation)
32
61
62
+ /** Enclose this message in an `Info` container */
33
63
def info (pos : SourcePosition ) =
34
64
new Info (self, pos, explanation)
35
65
66
+ /** Enclose this message in an `FeatureWarning` container */
36
67
def featureWarning (pos : SourcePosition ) =
37
68
new FeatureWarning (self, pos, explanation)
38
69
70
+ /** Enclose this message in an `UncheckedWarning` container */
39
71
def uncheckedWarning (pos : SourcePosition ) =
40
72
new UncheckedWarning (self, pos, explanation)
41
73
74
+ /** Enclose this message in an `DeprecationWarning` container */
42
75
def deprecationWarning (pos : SourcePosition ) =
43
76
new DeprecationWarning (self, pos, explanation)
44
77
78
+ /** Enclose this message in an `MigrationWarning` container */
45
79
def migrationWarning (pos : SourcePosition ) =
46
80
new MigrationWarning (self, pos, explanation)
47
81
}
48
82
83
+ /** The fallback `Message` containing no explanation and having no `kind` */
49
84
class NoExplanation (val msg : String ) extends Message (" " ) {
50
85
val explanation = " "
51
86
val kind = " "
52
87
}
53
88
89
+ /** The extractor for `NoExplanation` can be used to check whether any error
90
+ * lacks an explanation
91
+ */
54
92
object NoExplanation {
55
93
def unapply (m : Message ): Option [Message ] =
56
94
if (m.explanation == " " ) Some (m)
0 commit comments