Skip to content
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

[SR-4644] Create an expression for checking enum cases #47221

Open
swift-ci opened this issue Apr 20, 2017 · 5 comments
Open

[SR-4644] Create an expression for checking enum cases #47221

swift-ci opened this issue Apr 20, 2017 · 5 comments
Assignees
Labels
compiler The Swift compiler in itself expressions Feature: expressions feature A feature request or implementation pattern matching Feature: pattern matching swift evolution proposal needed Flag → feature: A feature that warrants a Swift evolution proposal

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-4644
Radar None
Original Reporter Reitzig (JIRA User)
Type Improvement
Status Closed
Resolution Invalid
Additional Detail from JIRA
Votes 5
Component/s Compiler
Labels Improvement, LanguageFeatureRequest
Assignee @lattner
Priority Medium

md5: 1f2f541a6eed36e3084232a2f9ea2ef1

duplicates:

  • SR-13601 Boolean-valued case checking expressions

is duplicated by:

  • SR-12381 Enum pattern matching in return statements

Issue Description:

Currently, we can use a (syntactically) special condition for checking if a value belongs to a certain enum case:

@swift-ci
Copy link
Collaborator Author

Comment by Raphael (JIRA)

Particularly nasty: checking if a collection of enum values contains a certain case:

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jun 1, 2018

Comment by Dave Yost (JIRA)

Seems clear that any expression that works as a condition in if, while, etc., is an expression with a Boolean value and therefore should be usable as a Boolean expression.

@swift-ci
Copy link
Collaborator Author

Comment by Suyeol Jeon (JIRA)

It would be really useful when writing test codes.

let value: MyEnum

// as-is
XCTAssertTrue({
  if case .myCase = value {
    return true
  }
  return false
}())

// to-be
XCTAssert(case .myCase = value)
XCTAssert(value.isCase(.myCase))

@lattner
Copy link
Mannequin

lattner mannequin commented Feb 8, 2020

This idea should be mediated by a proposal to swift evolution, not a bug sitting on me that I won't get a chance to do.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis
Copy link
Collaborator

Swapping statuses because this issue is older than its duplicate.

@AnthonyLatsis AnthonyLatsis reopened this Nov 11, 2022
@AnthonyLatsis AnthonyLatsis added parser Area → compiler: The legacy C++ parser good first issue Good for newcomers type checker Area → compiler: Semantic analysis SILGen Area → compiler: The SIL generation stage swift evolution proposal needed Flag → feature: A feature that warrants a Swift evolution proposal labels Nov 11, 2022
@AnthonyLatsis AnthonyLatsis added pattern matching Feature: pattern matching expressions Feature: expressions and removed good first issue Good for newcomers parser Area → compiler: The legacy C++ parser SILGen Area → compiler: The SIL generation stage type checker Area → compiler: Semantic analysis improvement labels Feb 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler in itself expressions Feature: expressions feature A feature request or implementation pattern matching Feature: pattern matching swift evolution proposal needed Flag → feature: A feature that warrants a Swift evolution proposal
Projects
None yet
Development

No branches or pull requests

2 participants