Skip to content

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

Open
@karwa

Description

@karwa
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfenumFeature → type declarations: Swift enumeration declarationspattern matchingFeature: pattern matchingswift 5.3swift 5.9type checkerArea → compiler: Semantic analysisunexpected errorBug: Unexpected error

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions