@@ -64,38 +64,90 @@ public extension ParserFixIt {
64
64
65
65
// MARK: - Errors (please sort alphabetically)
66
66
67
- /// Please order the cases in this enum alphabetically by case name.
68
- public enum StaticParserError : String , DiagnosticMessage {
69
- case allStatmentsInSwitchMustBeCoveredByCase = " all statements inside a switch must be covered by a 'case' or 'default' label "
70
- case caseOutsideOfSwitchOrEnum = " 'case' can only appear inside a 'switch' statement or 'enum' declaration "
71
- case consecutiveDeclarationsOnSameLine = " consecutive declarations on a line must be separated by ';' "
72
- case consecutiveStatementsOnSameLine = " consecutive statements on a line must be separated by ';' "
73
- case cStyleForLoop = " C-style for statement has been removed in Swift 3 "
74
- case defaultCannotBeUsedWithWhere = " 'default' cannot be used with a 'where' guard expression "
75
- case defaultOutsideOfSwitch = " 'default' label can only appear inside a 'switch' statement "
76
- case editorPlaceholderInSourceFile = " editor placeholder in source file "
77
- case expectedExpressionAfterTry = " expected expression after 'try' "
78
- case invalidFlagAfterPrecedenceGroupAssignment = " expected 'true' or 'false' after 'assignment' "
79
- case missingColonInTernaryExprDiagnostic = " expected ':' after '? ...' in ternary expression "
80
- case operatorShouldBeDeclaredWithoutBody = " operator should no longer be declared with body "
81
- case standaloneSemicolonStatement = " standalone ';' statements are not allowed "
82
- case subscriptsCannotHaveNames = " subscripts cannot have a name "
83
- case throwsInReturnPosition = " 'throws' may only occur before '->' "
84
- case tryMustBePlacedOnReturnedExpr = " 'try' must be placed on the returned expression "
85
- case tryMustBePlacedOnThrownExpr = " 'try' must be placed on the thrown expression "
86
- case tryOnInitialValueExpression = " 'try' must be placed on the initial value expression "
87
- case unexpectedSemicolon = " unexpected ';' separator "
88
- case associatedTypeCannotUsePack = " associated types cannot be variadic "
89
-
90
- public var message : String { self . rawValue }
67
+ /// A parser error with a static message.
68
+ public struct StaticParserError : DiagnosticMessage {
69
+ public let message : String
70
+ private let messageID : String
71
+
72
+ /// This should only be called within a static var on DiagnosticMessage, such
73
+ /// as the examples below. This allows us to pick up the messageID from the
74
+ /// var name.
75
+ fileprivate init ( _ message: String , messageID: String = #function) {
76
+ self . message = message
77
+ self . messageID = messageID
78
+ }
91
79
92
80
public var diagnosticID : MessageID {
93
- MessageID ( domain: diagnosticDomain, id: " \( type ( of: self ) ) . \( self ) " )
81
+ MessageID ( domain: diagnosticDomain, id: " \( type ( of: self ) ) . \( messageID ) " )
94
82
}
95
83
96
84
public var severity : DiagnosticSeverity { . error }
97
85
}
98
86
87
+ extension DiagnosticMessage where Self == StaticParserError {
88
+ /// Please order the diagnostics alphabetically by property name.
89
+ public static var allStatmentsInSwitchMustBeCoveredByCase : Self {
90
+ . init( " all statements inside a switch must be covered by a 'case' or 'default' label " )
91
+ }
92
+ public static var associatedTypeCannotUsePack : Self {
93
+ . init( " associated types cannot be variadic " )
94
+ }
95
+ public static var caseOutsideOfSwitchOrEnum : Self {
96
+ . init( " 'case' can only appear inside a 'switch' statement or 'enum' declaration " )
97
+ }
98
+ public static var consecutiveDeclarationsOnSameLine : Self {
99
+ . init( " consecutive declarations on a line must be separated by ';' " )
100
+ }
101
+ public static var consecutiveStatementsOnSameLine : Self {
102
+ . init( " consecutive statements on a line must be separated by ';' " )
103
+ }
104
+ public static var cStyleForLoop : Self {
105
+ . init( " C-style for statement has been removed in Swift 3 " )
106
+ }
107
+ public static var defaultCannotBeUsedWithWhere : Self {
108
+ . init( " 'default' cannot be used with a 'where' guard expression " )
109
+ }
110
+ public static var defaultOutsideOfSwitch : Self {
111
+ . init( " 'default' label can only appear inside a 'switch' statement " )
112
+ }
113
+ public static var editorPlaceholderInSourceFile : Self {
114
+ . init( " editor placeholder in source file " )
115
+ }
116
+ public static var expectedExpressionAfterTry : Self {
117
+ . init( " expected expression after 'try' " )
118
+ }
119
+ public static var invalidFlagAfterPrecedenceGroupAssignment : Self {
120
+ . init( " expected 'true' or 'false' after 'assignment' " )
121
+ }
122
+ public static var missingColonInTernaryExprDiagnostic : Self {
123
+ . init( " expected ':' after '? ...' in ternary expression " )
124
+ }
125
+ public static var operatorShouldBeDeclaredWithoutBody : Self {
126
+ . init( " operator should no longer be declared with body " )
127
+ }
128
+ public static var standaloneSemicolonStatement : Self {
129
+ . init( " standalone ';' statements are not allowed " )
130
+ }
131
+ public static var subscriptsCannotHaveNames : Self {
132
+ . init( " subscripts cannot have a name " )
133
+ }
134
+ public static var throwsInReturnPosition : Self {
135
+ . init( " 'throws' may only occur before '->' " )
136
+ }
137
+ public static var tryMustBePlacedOnReturnedExpr : Self {
138
+ . init( " 'try' must be placed on the returned expression " )
139
+ }
140
+ public static var tryMustBePlacedOnThrownExpr : Self {
141
+ . init( " 'try' must be placed on the thrown expression " )
142
+ }
143
+ public static var tryOnInitialValueExpression : Self {
144
+ . init( " 'try' must be placed on the initial value expression " )
145
+ }
146
+ public static var unexpectedSemicolon : Self {
147
+ . init( " unexpected ';' separator " )
148
+ }
149
+ }
150
+
99
151
// MARK: - Diagnostics (please sort alphabetically)
100
152
101
153
public struct EffectsSpecifierAfterArrow : ParserError {
0 commit comments