File tree Expand file tree Collapse file tree 3 files changed +35
-3
lines changed Expand file tree Collapse file tree 3 files changed +35
-3
lines changed Original file line number Diff line number Diff line change @@ -180,7 +180,7 @@ extension Parser {
180
180
}
181
181
182
182
let inheritance : RawTypeInheritanceClauseSyntax ?
183
- if self . at ( . colon) {
183
+ if self . at ( . colon) || self . at ( . leftParen ) {
184
184
inheritance = self . parseInheritance ( )
185
185
} else {
186
186
inheritance = nil
@@ -213,7 +213,16 @@ extension Parser {
213
213
/// Parse an inheritance clause.
214
214
@_spi ( RawSyntax)
215
215
public mutating func parseInheritance( ) -> RawTypeInheritanceClauseSyntax {
216
- let ( unexpectedBeforeColon, colon) = self . expect ( . colon)
216
+ let unexpectedBeforeColon : RawUnexpectedNodesSyntax ?
217
+ let colon : RawTokenSyntax
218
+ if self . at ( . colon) {
219
+ unexpectedBeforeColon = nil
220
+ colon = consumeAnyToken ( remapping: . colon)
221
+ } else {
222
+ unexpectedBeforeColon = RawUnexpectedNodesSyntax ( [ self . consumeAnyToken ( ) ] , arena: self . arena)
223
+ colon = missingToken ( . colon)
224
+ }
225
+
217
226
var elements = [ RawInheritedTypeSyntax] ( )
218
227
do {
219
228
var keepGoing : RawTokenSyntax ? = nil
@@ -241,6 +250,7 @@ extension Parser {
241
250
)
242
251
} while keepGoing != nil && loopProgress. evaluate ( currentToken)
243
252
}
253
+
244
254
return RawTypeInheritanceClauseSyntax (
245
255
unexpectedBeforeColon,
246
256
colon: colon,
Original file line number Diff line number Diff line change @@ -1171,7 +1171,26 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
1171
1171
return handleEffectSpecifiers ( node)
1172
1172
}
1173
1173
1174
- public override func visit( _ node: TypeInitializerClauseSyntax ) -> SyntaxVisitorContinueKind {
1174
+
1175
+
1176
+ public override func visit( _ node: TypeInheritanceClauseSyntax ) -> SyntaxVisitorContinueKind {
1177
+ if shouldSkip ( node) {
1178
+ return . skipChildren
1179
+ }
1180
+
1181
+ if let unexpected = node. unexpectedBeforeColon, !unexpected. tokens ( satisfying: { $0. tokenKind == . leftParen } ) . isEmpty {
1182
+ addDiagnostic ( unexpected,
1183
+ . expectedColonClass,
1184
+ fixIts: [ FixIt ( message: < #T##FixItMessage#> ,
1185
+ changes: [ FixIt . Changes. makePresent ( node. colon) , . makeMissing( unexpected) ] ) ] ,
1186
+ handledNodes: [ unexpected. id, node. colon. id]
1187
+ )
1188
+ }
1189
+
1190
+ return . visitChildren
1191
+ }
1192
+
1193
+ public override func visit( _ node: TypeInitializerClauseSyntax ) -> SyntaxVisitorContinueKind {
1175
1194
if shouldSkip ( node) {
1176
1195
return . skipChildren
1177
1196
}
Original file line number Diff line number Diff line change @@ -125,6 +125,9 @@ extension DiagnosticMessage where Self == StaticParserError {
125
125
public static var escapedNewlineAtLatlineOfMultiLineStringLiteralNotAllowed : Self {
126
126
. init( " escaped newline at the last line of a multi-line string literal is not allowed " )
127
127
}
128
+ public static var expectedColonClass : Self {
129
+ . init( " expected ':' to begin inheritance clause " )
130
+ }
128
131
public static var expectedExpressionAfterTry : Self {
129
132
. init( " expected expression after 'try' " )
130
133
}
You can’t perform that action at this time.
0 commit comments