[ASTGen] Handle #warning/#error in switch case position#90074
Open
nenadvulic wants to merge 5 commits into
Open
[ASTGen] Handle #warning/#error in switch case position#90074nenadvulic wants to merge 5 commits into
nenadvulic wants to merge 5 commits into
Conversation
Contributor
|
@swift-ci please smoke test |
Author
|
@hamishknight my mistake, I forgot to cover all cases. I'm checking it now |
Contributor
|
@swift-ci please smoke test |
Author
|
The smoke test caught a parser bug on the swift-syntax side, not here: a |
Allows the split closure of visitIfConfigElements to handle an element itself (e.g. evaluating a #warning/#error for its diagnostic) without producing a flat element to visit.
The parent of a pound diagnostic that appears in case position of a switch is a SwitchCaseListSyntax, so accept that parent kind instead of hitting the 'must be declaration level' assertion.
swift-syntax now parses #warning/#error in case position of a switch as a MacroExpansionDecl element of the case list (swiftlang/swift-syntax#3363). Generate the builtin pound for its diagnostic and skip it, since it is not a case.
Verify that pound diagnostics in case position (including inside an #if) are evaluated and not misparsed.
41e06a9 to
b4f636b
Compare
Contributor
|
@swift-ci please smoke test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Companion to swiftlang/swift-syntax#3363.
That PR makes swift-syntax parse
#warning/#errorin case position of aswitchas aMacroExpansionDeclelement of the case list (instead of diagnosing them), to match the compiler. As a resultSwitchCaseListSyntax.Elementgains a.macroExpansionDeclcase, which makes the exhaustive switch ingenerate(switchCaseList:)no longer compile.This handles the new case in ASTGen:
Stmts.swift: ingenerate(switchCaseList:), handle.macroExpansionDeclby evaluating it withmaybeGenerateBuiltinPound(for the#warning/#errordiagnostic) and skipping it, since it isn't a case.ASTGen+CompilerBuildConfiguration.swift: add askipcase toIfConfigOrUnderlyingso thesplitclosure can handle an element itself without producing a flat element to visit.BuiltinPound.swift:handlePoundDiagnosticasserted that a pound diagnostic must be at code-block/member-block level; the parent in this case is aSwitchCaseListSyntax, so accept that parent kind too.Added an ASTGen test covering
#warning/#errorin case position, including inside an#if.This only builds against the swift-syntax branch above, so it needs to be cross-repo tested with it.