Skip to content

[SE-0521] Parse some P? and any P? as (some P)? and (any P)?.#3268

Open
allevato wants to merge 1 commit into
swiftlang:mainfrom
allevato:optional-someany
Open

[SE-0521] Parse some P? and any P? as (some P)? and (any P)?.#3268
allevato wants to merge 1 commit into
swiftlang:mainfrom
allevato:optional-someany

Conversation

@allevato
Copy link
Copy Markdown
Member

@allevato allevato commented Feb 13, 2026

swift-syntax parser implementation of SE-0521. Companion of swiftlang/swift#87115.

@allevato allevato changed the title [WIP] Parse some P? and any P? as (some P)? and (any P)?. [SE-0521] Parse some P? and any P? as (some P)? and (any P)?. Apr 22, 2026
@allevato allevato marked this pull request as ready for review April 22, 2026 13:21
@allevato allevato requested a review from a team as a code owner April 22, 2026 13:21
@allevato
Copy link
Copy Markdown
Member Author

SE-0521 was accepted so this is ready for review as a candidate for 6.4.

@DougGregor
Copy link
Copy Markdown
Member

@swift-ci please test

@DougGregor
Copy link
Copy Markdown
Member

@swift-ci please test Windows

1 similar comment
@DougGregor
Copy link
Copy Markdown
Member

@swift-ci please test Windows

@nkcsgexi nkcsgexi requested a review from rintaro May 14, 2026 20:47
return token
}
return token.tokenView.withTokenDiagnostic(
tokenDiagnostic: TokenDiagnostic(.ambiguousOptionalAfterSomeOrAnyComposition, byteOffset: 0),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

TokenDiagnostics is designed for diagnostics that must be attached to a token, like Lexer diagnostics or whitespace diagnostics because syntax tree structure can't carry the information.
In this case, instead of using it, you could you make RawTupleTypeSyntax with missing (/) and the single base element? ParserDiagnosticsGenerator should be able to catch the pattern and diagnose it.

while self.hasProgressed(&loopProgress) {
if self.at(.postfixQuestionMark) {
var optional = self.parseOptionalType(base)
optional = RawOptionalTypeSyntax(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please try to avoid rewriting parsed node. Nodes are allocated in a bump pointer allocator. We don't want to waste it.
This block can be something like:

        if self.at(.postfixQuestionMark) {
          base = wrapCompositionInMissingParensIfNeeded(base)
          base = RawTypeSyntax(self.parseOptionalType(base))
        } else if self.at(.exclamationMark) {
          base = wrapCompositionInMissingParensIfNeeded(base)
          base = RawTypeSyntax(self.parseImplicitlyUnwrappedOptionalType(base))
        } else {
          break
        }

where wrapCompositionInMissingParensIfNeeded only wraps base if it is a SomeOrAnyType wrapping CompositionType.

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.

3 participants