Repository navigation
[SwiftParser] Accept keyword-named decl references after a module selector in atStartOfExpression - #3406
Merged
Conversation
…ector in atStartOfExpression 'atStartOfExpression()' consumes a module selector and then recursively tests whether the following token can begin an unqualified expression, so lexer-classified keywords such as 'as' and 'is' fail the check and valid code like 'Module::as(x)' at statement level is parsed as unexpected code. 'parseDeclReferenceBase()' already accepts any lexer-classified keyword after a module selector and remaps it to an identifier; teach the lookahead the same rule so the two agree. Fixes swiftlang#3387
Contributor
Author
|
This has been open a couple of weeks with no CI run yet. Whenever someone has a moment, could a maintainer kick off |
Member
|
@swift-ci Please test |
rintaro
approved these changes
Sep 9, 2026
rintaro
left a comment
Member
There was a problem hiding this comment.
Sorry for the delay. This looks good to me. Thank you!
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.
Fixes #3387.
Problem
atStartOfExpression()consumes a module selector and then recursively tests whether the following token can begin an unqualified expression. Lexer-classified keywords such asasandisfail that check, so valid code the compiler accepts:is parsed at statement level as unexpected code instead of a
FunctionCallExprSyntax, with a spurious diagnostic.Fix
parseDeclReferenceBase()already accepts any lexer-classified keyword after a module selector and remaps it to an identifier. This teaches the lookahead the same rule: after consuming the module selector tokens, a lexer-classified keyword counts as the start of an expression. Six lines, no behavior change for code without module selectors.Testing
Added
testModuleSelectorKeywordNameAtStartOfStatementtoModuleSelectorTestscoveringModule::as(x)andModule::is(x)as bare statements plus the issue's function-body reproducer, asserting theFunctionCallExprSyntaxsubstructure with the module-selectedDeclReferenceExprSyntaxcallee and no diagnostics.FunctionCallExprSyntax; one diagnostic each) — matching the issue.SKIP_LONG_TESTS=1, Swift 6.3 / aarch64 Linux).