[SE-0521] Parse some P? and any P? as (some P)? and (any P)?.#3268
[SE-0521] Parse some P? and any P? as (some P)? and (any P)?.#3268allevato wants to merge 1 commit into
some P? and any P? as (some P)? and (any P)?.#3268Conversation
c517c44 to
3e8deb8
Compare
some P? and any P? as (some P)? and (any P)?.some P? and any P? as (some P)? and (any P)?.
|
SE-0521 was accepted so this is ready for review as a candidate for 6.4. |
|
@swift-ci please test |
|
@swift-ci please test Windows |
1 similar comment
|
@swift-ci please test Windows |
| return token | ||
| } | ||
| return token.tokenView.withTokenDiagnostic( | ||
| tokenDiagnostic: TokenDiagnostic(.ambiguousOptionalAfterSomeOrAnyComposition, byteOffset: 0), |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
swift-syntax parser implementation of SE-0521. Companion of swiftlang/swift#87115.