Skip to content

Commit af40c61

Browse files
committed
Fix Regression in Leading Trivia for Declarations
This was introduced while migrating their introducers from eat to expect.
1 parent 689eb41 commit af40c61

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

Sources/SwiftParser/Declarations.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ extension Parser {
577577
return RawClassDeclSyntax(
578578
attributes: attrs.attributes,
579579
modifiers: attrs.modifiers,
580+
unexpectedBeforeClassKeyword,
580581
classKeyword: classKeyword,
581582
unexpectedBeforeName,
582583
identifier: name,
@@ -694,6 +695,7 @@ extension Parser {
694695
let members = self.parseMemberDeclList()
695696
return RawEnumDeclSyntax(
696697
attributes: attrs.attributes, modifiers: attrs.modifiers,
698+
unexpectedBeforeEnumKeyword,
697699
enumKeyword: enumKeyword,
698700
unexpectedBeforeName,
699701
identifier: name,
@@ -831,6 +833,7 @@ extension Parser {
831833
let members = self.parseMemberDeclList()
832834
return RawStructDeclSyntax(
833835
attributes: attrs.attributes, modifiers: attrs.modifiers,
836+
unexpectedBeforeStructKeyword,
834837
structKeyword: structKeyword,
835838
identifier: name,
836839
genericParameterClause: generics,
@@ -938,6 +941,7 @@ extension Parser {
938941

939942
return RawProtocolDeclSyntax(
940943
attributes: attrs.attributes, modifiers: attrs.modifiers,
944+
unexpectedBeforeProtocolKeyword,
941945
protocolKeyword: protocolKeyword,
942946
identifier: name,
943947
primaryAssociatedTypeClause: primaries,
@@ -1003,6 +1007,7 @@ extension Parser {
10031007

10041008
return RawAssociatedtypeDeclSyntax(
10051009
attributes: attrs.attributes, modifiers: attrs.modifiers,
1010+
unexpectedBeforeAssocKeyword,
10061011
associatedtypeKeyword: assocKeyword,
10071012
identifier: name,
10081013
inheritanceClause: inheritance,

Tests/SwiftParserTest/Declarations.swift

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,55 @@ final class DeclarationTests: XCTestCase {
782782
}
783783
"""##)
784784
}
785+
786+
func testLeadingUnexpectedTokens() {
787+
AssertParse("#^DIAG_1^#}class C#^DIAG_2^#",
788+
diagnostics: [
789+
DiagnosticSpec(locationMarker: "DIAG_1", message: "Unexpected text '}' found in class"),
790+
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected '{' to start class"),
791+
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected '}' to end class"),
792+
])
793+
AssertParse("#^DIAG_1^#}enum C#^DIAG_2^#",
794+
diagnostics: [
795+
DiagnosticSpec(locationMarker: "DIAG_1", message: "Unexpected text '}' found in enum"),
796+
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected '{' to start enum"),
797+
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected '}' to end enum"),
798+
])
799+
AssertParse("#^DIAG_1^#}protocol C#^DIAG_2^#",
800+
diagnostics: [
801+
DiagnosticSpec(locationMarker: "DIAG_1", message: "Unexpected text '}' found in protocol"),
802+
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected '{' to start protocol"),
803+
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected '}' to end protocol"),
804+
])
805+
AssertParse("#^DIAG_1^#}actor C#^DIAG_2^#",
806+
diagnostics: [
807+
DiagnosticSpec(locationMarker: "DIAG_1", message: "Unexpected text '}' found in actor"),
808+
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected '{' to start actor"),
809+
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected '}' to end actor"),
810+
])
811+
AssertParse("#^DIAG_1^#}struct C#^DIAG_2^#",
812+
diagnostics: [
813+
DiagnosticSpec(locationMarker: "DIAG_1", message: "Unexpected text '}' found in struct"),
814+
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected '{' to start struct"),
815+
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected '}' to end struct"),
816+
])
817+
AssertParse("#^DIAG_1^#}func C#^DIAG_2^#",
818+
diagnostics: [
819+
DiagnosticSpec(locationMarker: "DIAG_1", message: "Unexpected text '}' found in function"),
820+
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected argument list in function declaration"),
821+
])
822+
AssertParse("#^DIAG_1^#}init#^DIAG_2^#",
823+
diagnostics: [
824+
DiagnosticSpec(locationMarker: "DIAG_1", message: "Unexpected text '}' found in initializer"),
825+
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected argument list in function declaration"),
826+
])
827+
AssertParse("#^DIAG_1^#}subscript#^DIAG_2^#",
828+
diagnostics: [
829+
DiagnosticSpec(locationMarker: "DIAG_1", message: "Unexpected text '}' found in subscript"),
830+
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected argument list in function declaration"),
831+
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected '->' in return clause"),
832+
])
833+
}
785834
}
786835

787836
extension Parser.DeclAttributes {

0 commit comments

Comments
 (0)