Skip to content

Only allow postfixQuestionMark as the question mark after init #1985

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 1 commit into from
Aug 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,6 @@ public let DECL_NODES: [Node] = [
name: "optionalMark",
kind: .token(choices: [
.token(.postfixQuestionMark),
.token(.infixQuestionMark),
.token(.exclamationMark),
]),
documentation: "If the initializer is failable, a question mark to indicate that.",
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftParser/Declarations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ extension Parser {

// Parse the '!' or '?' for a failable initializer.
let failable: RawTokenSyntax?
if let parsedFailable = self.consume(if: .exclamationMark, .postfixQuestionMark, .infixQuestionMark) {
if let parsedFailable = self.consume(if: .exclamationMark, .postfixQuestionMark, TokenSpec(.infixQuestionMark, remapping: .postfixQuestionMark)) {
failable = parsedFailable
} else if let parsedFailable = self.consumeIfContextualPunctuator("!", remapping: .exclamationMark) {
failable = parsedFailable
Expand Down
7 changes: 0 additions & 7 deletions Sources/SwiftParser/generated/Parser+TokenSpecSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1807,15 +1807,12 @@ extension InitializerDeclSyntax {
@_spi(Diagnostics)
public enum OptionalMarkOptions: TokenSpecSet {
case postfixQuestionMark
case infixQuestionMark
case exclamationMark

init?(lexeme: Lexer.Lexeme) {
switch PrepareForKeywordMatch(lexeme) {
case TokenSpec(.postfixQuestionMark):
self = .postfixQuestionMark
case TokenSpec(.infixQuestionMark):
self = .infixQuestionMark
case TokenSpec(.exclamationMark):
self = .exclamationMark
default:
Expand All @@ -1827,8 +1824,6 @@ extension InitializerDeclSyntax {
switch self {
case .postfixQuestionMark:
return .postfixQuestionMark
case .infixQuestionMark:
return .infixQuestionMark
case .exclamationMark:
return .exclamationMark
}
Expand All @@ -1842,8 +1837,6 @@ extension InitializerDeclSyntax {
switch self {
case .postfixQuestionMark:
return .postfixQuestionMarkToken()
case .infixQuestionMark:
return .infixQuestionMarkToken()
case .exclamationMark:
return .exclamationMarkToken()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1553,7 +1553,7 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) {
assertNoError(kind, 4, verify(layout[4], as: RawUnexpectedNodesSyntax?.self))
assertNoError(kind, 5, verify(layout[5], as: RawTokenSyntax.self, tokenChoices: [.keyword("init")]))
assertNoError(kind, 6, verify(layout[6], as: RawUnexpectedNodesSyntax?.self))
assertNoError(kind, 7, verify(layout[7], as: RawTokenSyntax?.self, tokenChoices: [.tokenKind(.postfixQuestionMark), .tokenKind(.infixQuestionMark), .tokenKind(.exclamationMark)]))
assertNoError(kind, 7, verify(layout[7], as: RawTokenSyntax?.self, tokenChoices: [.tokenKind(.postfixQuestionMark), .tokenKind(.exclamationMark)]))
assertNoError(kind, 8, verify(layout[8], as: RawUnexpectedNodesSyntax?.self))
assertNoError(kind, 9, verify(layout[9], as: RawGenericParameterClauseSyntax?.self))
assertNoError(kind, 10, verify(layout[10], as: RawUnexpectedNodesSyntax?.self))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3787,7 +3787,7 @@ public struct InitializerClauseSyntax: SyntaxProtocol, SyntaxHashable {
/// - `attributes`: ``AttributeListSyntax``
/// - `modifiers`: ``DeclModifierListSyntax``
/// - `initKeyword`: `'init'`
/// - `optionalMark`: (`'?'` | `'?'` | `'!'`)?
/// - `optionalMark`: (`'?'` | `'!'`)?
/// - `genericParameterClause`: ``GenericParameterClauseSyntax``?
/// - `signature`: ``FunctionSignatureSyntax``
/// - `genericWhereClause`: ``GenericWhereClauseSyntax``?
Expand Down