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

Trailing closures are wrongly accepted for enum-case-patterns #79047

Open
rintaro opened this issue Jan 30, 2025 · 0 comments
Open

Trailing closures are wrongly accepted for enum-case-patterns #79047

rintaro opened this issue Jan 30, 2025 · 0 comments
Labels
accepts invalid Bug: Accepts invalid bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. closures Feature: closures compiler The Swift compiler itself enum case patterns Feature → patterns: Enumeration case patterns patterns Feature: patterns Swift 6.2-dev type checker Area → compiler: Semantic analysis

Comments

@rintaro
Copy link
Member

rintaro commented Jan 30, 2025

Description

According to the document, if an enum case pattern includes a sub-pattern, it must be a tuple pattern, which should always be enclosed in parentheses.

https://docs.swift.org/swift-book/documentation/the-swift-programming-language/patterns/#Enumeration-Case-Pattern

enum-case-pattern → type-identifier? . enum-case-name tuple-pattern?
tuple-pattern → ( tuple-pattern-element-list? )

But, matching patterns like case .foo { true }: is accepted.

Reproduction

func ~= <T>(_ lhs: () -> Bool, rhs: T) -> Bool { true }

enum E {
  case foo(Int)
}

func test(v: E) {
  switch v {
    case .foo { true } : break
    default: break
  }
}

Expected behavior

Compiler should diagnose it, or documentation should be corrected to accept trailing closures.

Environment

Swift version 6.0.3

Additional information

No response

@rintaro rintaro added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Jan 30, 2025
@AnthonyLatsis AnthonyLatsis added compiler The Swift compiler itself type checker Area → compiler: Semantic analysis accepts invalid Bug: Accepts invalid closures Feature: closures patterns Feature: patterns enum case patterns Feature → patterns: Enumeration case patterns Swift 6.2-dev and removed triage needed This issue needs more specific labels labels Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepts invalid Bug: Accepts invalid bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. closures Feature: closures compiler The Swift compiler itself enum case patterns Feature → patterns: Enumeration case patterns patterns Feature: patterns Swift 6.2-dev type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants