You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consider the following code:
```swift
}
@ATTR1 func foo() {}
```
Previously, this was parsed as a `FunctionDeclSyntax` with the unexpected
code `} @attr` attached as `unexpectedBeforeFuncKeyword`. This was
problematic because `@attr` was effectively ignored. The
`TokenPrecedence`-based recovery strategy couldn't handle this well, since
`@` is not a declaration keyword and doesn't by itself signal the start
of a declaration.
One option would be to check `atStartOfDeclaration()` after each
`skipSingle()` and recognize `@` as the start of a declaration. However,
then the preceding `}` would need to be attached to the first attribute in
the attribute list, which would require threading recovery logic into
`parseAttributeList()` and only applying it to the first `parseAttribute()`.
This would make the code more complex and harder to maintain.
This PR introduces a new syntax node `UnexpectedCodeDeclSyntax`
* It represents unexpected code at the statement/declaration level.
* All statement-level recovery is now handled by `parseUnexpectedCodeDeclaration()`.
This simplifies recovery handling significantly.
---
Also:
* Improve `#if` related recovery:
* orphan `#endif` et al at top-level is now `UnexpectedCodeDecl` instead
of making everything after it "unexpected"
```swift
#endif
func foo() {}
```
* Unbalanced `#endif` et al closes code/member block with missing `}`.
```swift
struct S {
#if FOO
func foo() {
#endif
}
```
* Simplified `parsePoundDirective()`. It now receives only one closure
instead of 3.
* Don't attach ';' to compiler directives. For example:
```swift
#sourceLocation(file: "<file>", line: 100)
;
```
`;` is now diagnosed as `;`-only statement, or unexpected `;` separator
depending on the position.
* Adjust TokenPrecedence for decl/statement keyword so. Decl keyword
recovery won't go beyond `}` or statements. E.g.
```swift
func foo() {
@attr
}
struct S {}
```
```swift
func foo() {
@attr
if true {}
struct S {}
}
```
0 commit comments