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-7792] Odd Name Lookup in Switch Statements #50331

Open
jawbroken opened this issue May 28, 2018 · 4 comments
Open

[SR-7792] Odd Name Lookup in Switch Statements #50331

jawbroken opened this issue May 28, 2018 · 4 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@jawbroken
Copy link

Previous ID SR-7792
Radar rdar://problem/41495564
Original Reporter @jawbroken
Type Bug
Environment

Xcode Version 9.3.1 (9E501)

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

md5: 975f95ad72ab1feb8da2706157ab7a00

Issue Description:

Name lookup in switch statements seems buggy. I'll demonstrate the issue with a few examples, showing issues ranging from bad diagnostics to what I consider to be bugs:

enum A { case one }
enum B { case one }

let e = A.one

switch e {
  case A.one: print("one")
  case B.one: print("one") // error: Enum case 'one' is not a member of type 'A'
}
enum A { case one }

let e: A? = A.one

switch e {
  case A.one: print("one") // error: Enum case 'one' is not a member of type 'A?'
}
struct S {
  var i: Int
  static var ten: S { return S(i: 10)}
}

let s: S? = .ten

switch s {
  case .ten: print("ten") // error: enum case 'ten' not found in type 'S?'
  default: print("default")
}

You can see more examples and some discussion in this forum thread.

@CodaFi
Copy link
Member

CodaFi commented May 28, 2018

Mirroring my response from the forum post: The diagnostics are bad, but this is not a bug. Optional upcasting and other implicit conversions are not a feature of pattern matching, so you have to spell out .some or ?.

@jawbroken
Copy link
Author

Okay, then I'll also mirror my examples of what seems to me like optional upcasting and implicit conversion in switch statements here:

let optionalInt: Int? = 1

switch optionalInt {
  case 1: print("one")
  default: print("default")
}

switch optionalInt {
  case (1 as Int): print("one")
  default: print("default")
}

let one: Int = 1

switch optionalInt {
  case one: print("one")
  default: print("default")
}

I'm probably missing something obvious, but I'm having trouble determining the model here.

@belkadan
Copy link
Contributor

This is a bug. B.one does in fact look up A.one, which is wrong. I'll find the dup later.

@belkadan
Copy link
Contributor

I can't find the dup, so I guess this bug will have to do.

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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
Projects
None yet
Development

No branches or pull requests

3 participants