Skip to content

[Macros] Centralize "unwrapping" of errors into diagnostics. #1469

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
merged 2 commits into from
Mar 31, 2023

Conversation

DougGregor
Copy link
Member

We had a few different implementations of "take an error thrown from a
macro and turn it into diagnostics". Improve the implementation in
MacroExpansionContext.addDiagnostics to properly handle both
DiagnosticsError and DiagnosticsMessage, as well as fall back
gracefully if either of those is missing an error diagnostic. Then,
use that implementation for the compiler plugin message handler.

Another part of fixing rdar://107289985, where diagnostics provided by
throwing DiagnosticsError aren't coming through well.

We had a few different implementations of "take an error thrown from a
macro and turn it into diagnostics". Improve the implementation in
`MacroExpansionContext.addDiagnostics` to properly handle both
`DiagnosticsError` and `DiagnosticsMessage`, as well as fall back
gracefully if either of those is missing an error diagnostic. Then,
use that implementation for the compiler plugin message handler.

Another part of fixing rdar://107289985, where diagnostics provided by
throwing `DiagnosticsError` aren't coming through well.
@DougGregor DougGregor requested a review from ahoppen as a code owner March 30, 2023 21:02
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please test macOS

// handle possibility that none of the diagnostics was an error
if !diagnosticsError.diagnostics.contains(
// Handle possibility that none of the diagnostics was an error.
if !diagnostics.contains(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this is actually used now for the DiagnosticMessage case 😅!

@DougGregor DougGregor merged commit e5178e2 into swiftlang:main Mar 31, 2023
@DougGregor DougGregor deleted the macro-context-add-diags branch March 31, 2023 00:22
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.

2 participants