File tree Expand file tree Collapse file tree 2 files changed +25
-12
lines changed
Sources/SwiftParser/Diagnostics
Tests/SwiftParserTest/translated Expand file tree Collapse file tree 2 files changed +25
-12
lines changed Original file line number Diff line number Diff line change @@ -42,11 +42,19 @@ fileprivate enum NodesDescriptionPart {
42
42
}
43
43
return token. tokenKind. decomposeToRaw ( ) . rawKind. nameForDiagnostics
44
44
case . node( let node) :
45
- if let childName = node. childNameInParent {
46
- return childName
47
- } else {
48
- return node. nodeTypeNameForDiagnostics ( allowBlockNames: true )
45
+ var walk : Syntax = node
46
+ while true {
47
+ if let childName = walk. childNameInParent {
48
+ return childName
49
+ }
50
+ if let parent = walk. parent, parent. children ( viewMode: . all) . count == 1 {
51
+ // If walk is the only node in its parent, check if that parent has a childNameForDiagnostics
52
+ walk = parent
53
+ } else {
54
+ break
55
+ }
49
56
}
57
+ return node. nodeTypeNameForDiagnostics ( allowBlockNames: true )
50
58
}
51
59
}
52
60
Original file line number Diff line number Diff line change @@ -9,18 +9,23 @@ final class GuardTests: XCTestCase {
9
9
func noConditionNoElse() {
10
10
guard {} 1️⃣
11
11
}
12
- func noCondition() {
13
- guard 2️⃣else {}
14
- }3️⃣
15
12
""" ,
16
13
diagnostics: [
17
- // TODO: Old parser expected error on line 2: missing condition in 'guard' statement
18
- // TODO: Old parser expected error on line 2: expected 'else' after 'guard' condition
19
- DiagnosticSpec ( locationMarker: " 1️⃣ " , message: " expected 'else' and body in 'guard' statement " ) ,
20
- // TODO: Old parser expected error on line 5: missing condition in 'guard' statement
21
- DiagnosticSpec ( locationMarker: " 2️⃣ " , message: " expected expression in 'guard' statement " ) ,
14
+ DiagnosticSpec ( message: " expected 'else' and body in 'guard' statement " ) ,
22
15
]
23
16
)
24
17
}
25
18
19
+ func testGuard2( ) {
20
+ AssertParse (
21
+ """
22
+ func noCondition() {
23
+ guard 1️⃣else {}
24
+ }
25
+ """ ,
26
+ diagnostics: [
27
+ DiagnosticSpec ( message: " expected conditions in 'guard' statement " ) ,
28
+ ]
29
+ )
30
+ }
26
31
}
You can’t perform that action at this time.
0 commit comments