Skip to content

Make OptionalBindingCondition and MatchingPatternCondition expressible as ConditionElement #525

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 2 commits into from
Jul 27, 2022

Conversation

fwcd
Copy link
Member

@fwcd fwcd commented Jul 27, 2022

As proposed in #506 (comment), this conforms ExpressibleAsOptionalBindingCondition and ExpressibleAsMatchingPatternCondition to ExpressibleAsConditionElement, making it more convenient to express if-let and if-case statements with the DSL:

// if let x = y { ... }
IfStmt(
  conditions: OptionalBindingCondition(
    letOrVarKeyword: .let,
    pattern: "x",
    initializer: InitializerClause(value: "y")
  )
) { ... }

// if case .x = y { ... }
IfStmt(
  conditions: MatchingPatternCondition(
    pattern: ExpressionPattern(expression: MemberAccessExpr(name: "x")),
    initializer: InitializerClause(value: "y")
  )
) { ... }

@fwcd fwcd requested a review from ahoppen as a code owner July 27, 2022 15:44
@fwcd
Copy link
Member Author

fwcd commented Jul 27, 2022

@swift-ci please test

@fwcd fwcd force-pushed the expressible-condition-elements branch from 64b5335 to 7262a36 Compare July 27, 2022 21:37
@fwcd
Copy link
Member Author

fwcd commented Jul 27, 2022

@swift-ci please test

@fwcd fwcd merged commit 4c9dc69 into swiftlang:main Jul 27, 2022
@fwcd fwcd deleted the expressible-condition-elements branch July 27, 2022 23:51
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.

2 participants