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-14258] Pattern-matching fails when enum case is type-qualified #56618

Open
karwa opened this issue Feb 19, 2021 · 2 comments
Open

[SR-14258] Pattern-matching fails when enum case is type-qualified #56618

karwa opened this issue Feb 19, 2021 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself enum Feature → type declarations: Swift enumeration declarations pattern matching Feature: pattern matching swift 5.3 swift 5.9 type checker Area → compiler: Semantic analysis unexpected error Bug: Unexpected error

Comments

@karwa
Copy link
Contributor

karwa commented Feb 19, 2021

Previous ID SR-14258
Radar rdar://problem/74616577
Original Reporter @karwa
Type Bug
Environment

Xcode Version 12.4 (12D4e)

macOS 10.15.7 (19H15)

Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28)

Target: x86_64-apple-darwin19.6.0

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 44f7392d58ba8233dcd512e04b5c643a

Issue Description:

enum Demo {
  case foo
  case bar
  case baz
}


func ~= (pattern: Demo, value: String) -> Bool {
  false
}


func a() {
  switch "" {
  case .foo, .bar:
    break
  case Demo.baz:   // < ERROR: Enum case 'baz' is not a member of type 'String'
    break
  default:
    break
  }
}

When referring to cases as ".foo" or ".bar", all is well. However, when using the type-qualified spelling "Demo.baz", the code fails to compile. Moreover, the diagnostic tells us that it... expects 'baz' to exist on String... but it knows its an enum case, soo... it must have seen the definition in 'Demo'? So why is it looking in String?

Weirdness.

@typesanitizer
Copy link

@swift-ci create

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

ole commented Mar 16, 2023

Manual backlink: this issue was mentioned in this forum thread: How does ‘switch’ work? Not the same as if/else with pattern matching operator

@AnthonyLatsis AnthonyLatsis added type checker Area → compiler: Semantic analysis enum Feature → type declarations: Swift enumeration declarations pattern matching Feature: pattern matching unexpected error Bug: Unexpected error swift 5.3 swift 5.9 labels Mar 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself enum Feature → type declarations: Swift enumeration declarations pattern matching Feature: pattern matching swift 5.3 swift 5.9 type checker Area → compiler: Semantic analysis unexpected error Bug: Unexpected error
Projects
None yet
Development

No branches or pull requests

4 participants