File tree 4 files changed +30
-4
lines changed
Tests/SwiftParserTest/translated
4 files changed +30
-4
lines changed Original file line number Diff line number Diff line change @@ -995,7 +995,7 @@ extension Parser {
995
995
}
996
996
997
997
// Parse the signature.
998
- let signature = self . parseFunctionSignature ( )
998
+ let signature = self . parseFunctionSignature ( allowOutput : false )
999
999
1000
1000
let whereClause : RawGenericWhereClauseSyntax ?
1001
1001
if self . at ( . keyword( . where) ) {
@@ -1159,7 +1159,7 @@ extension Parser {
1159
1159
)
1160
1160
}
1161
1161
1162
- mutating func parseFunctionSignature( ) -> RawFunctionSignatureSyntax {
1162
+ mutating func parseFunctionSignature( allowOutput : Bool = true ) -> RawFunctionSignatureSyntax {
1163
1163
let parameterClause = self . parseParameterClause ( RawFunctionParameterClauseSyntax . self) { parser in
1164
1164
parser. parseFunctionParameter ( )
1165
1165
}
@@ -1179,10 +1179,19 @@ extension Parser {
1179
1179
returnClause = nil
1180
1180
}
1181
1181
1182
+ var unexpectedAfterReturnClause : RawUnexpectedNodesSyntax ?
1183
+ if !allowOutput,
1184
+ let unexpectedOutput = returnClause
1185
+ {
1186
+ returnClause = nil
1187
+ unexpectedAfterReturnClause = RawUnexpectedNodesSyntax ( [ unexpectedOutput] , arena: self . arena)
1188
+ }
1189
+
1182
1190
return RawFunctionSignatureSyntax (
1183
1191
parameterClause: parameterClause,
1184
1192
effectSpecifiers: effectSpecifiers,
1185
1193
returnClause: returnClause,
1194
+ unexpectedAfterReturnClause,
1186
1195
arena: self . arena
1187
1196
)
1188
1197
}
Original file line number Diff line number Diff line change @@ -1273,6 +1273,14 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
1273
1273
)
1274
1274
}
1275
1275
1276
+ if let unexpectedOutput = node. signature. unexpectedAfterReturnClause {
1277
+ addDiagnostic (
1278
+ unexpectedOutput,
1279
+ . initializerCannotHaveResultType,
1280
+ handledNodes: [ unexpectedOutput. id]
1281
+ )
1282
+ }
1283
+
1276
1284
return . visitChildren
1277
1285
}
1278
1286
Original file line number Diff line number Diff line change @@ -176,6 +176,9 @@ extension DiagnosticMessage where Self == StaticParserError {
176
176
public static var initializerCannotHaveName : Self {
177
177
. init( " initializers cannot have a name " )
178
178
}
179
+ public static var initializerCannotHaveResultType : Self {
180
+ . init( " initializers cannot have a result type " )
181
+ }
179
182
public static var invalidFlagAfterPrecedenceGroupAssignment : Self {
180
183
. init( " expected 'true' or 'false' after 'assignment' " )
181
184
}
Original file line number Diff line number Diff line change @@ -104,7 +104,10 @@ final class InitDeinitTests: ParserTestCase {
104
104
struct FooStructConstructorD {
105
105
init() 1️⃣-> FooStructConstructorD { }
106
106
}
107
- """
107
+ """ ,
108
+ diagnostics: [
109
+ DiagnosticSpec ( message: " initializers cannot have a result type " )
110
+ ]
108
111
)
109
112
}
110
113
@@ -422,7 +425,10 @@ final class InitDeinitTests: ParserTestCase {
422
425
assertParse (
423
426
"""
424
427
init(_ foo: T) 1️⃣-> Int where T: Comparable {}
425
- """
428
+ """ ,
429
+ diagnostics: [
430
+ DiagnosticSpec ( message: " initializers cannot have a result type " )
431
+ ]
426
432
)
427
433
}
428
434
You can’t perform that action at this time.
0 commit comments