Skip to content

[509] Fix issue that caused errors thrown from macro expansion to show up twice in MacroSystem #2135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Sep 1, 2023

Cherry-pick #2115 to package-release/509.


If the macro expansion of a freestanding expression macro throws an error, expandCodeBlockItem returned nil while adding the thrown error to the macro expansion context. visit(_:CodeBlockItemListSyntax).addResult took the nil return value as an indicator that the macro wasn’t expanded because its macro definition wasn’t found and ended up calling the expansion again in

// Recurse on the child node
newItems.append(visit(node))

Change the return value of expandCodeBlockItem to an enum that indicates whether the macro was not found or if the expansion failed. If the macro was found but the expansion threw an error, we just just retain the macro as-is without calling into visit again.

Fixes #2111
rdar://114592410

…wice in MacroSystem

If the macro expansion of a freestanding expression macro throws an error, `expandCodeBlockItem` returned `nil` while adding the thrown error to the macro expansion context. `visit(_:CodeBlockItemListSyntax).addResult` took the `nil` return value as an indicator that the macro wasn’t expanded because its macro definition wasn’t found and ended up calling the expansion again in

```swift
// Recurse on the child node
newItems.append(visit(node))
```

Change the return value of `expandCodeBlockItem` to an enum that indicates whether the macro was not found or if the expansion failed. If the macro was found but the expansion threw an error, we just just retain the macro as-is without calling into `visit` again.

Fixes swiftlang#2111
rdar://114592410
@ahoppen ahoppen merged commit 23be62c into swiftlang:package-release/509 Sep 1, 2023
@ahoppen ahoppen deleted the ahoppen/509/multiple-errors branch September 1, 2023 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant