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-14276] Enum static variable naming #56635

Closed
swift-ci opened this issue Feb 26, 2021 · 2 comments
Closed

[SR-14276] Enum static variable naming #56635

swift-ci opened this issue Feb 26, 2021 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-14276
Radar None
Original Reporter dorjeozer (JIRA User)
Type Bug
Status Resolved
Resolution Invalid
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: c6b9cbdeb816022bc0c82f678d2fa2b4

Issue Description:

It's still a bit unclear if this is a bug or a feature, but anyhow Swift allows to use same names in Enums for cases and static variables, but only if the type is explicitely defined to the variable before it's value is initialized.

So the question is that should enum allow same names for cases and static variables, and if so should this fllowing compiler error to be resolved?

Here's the example:

enum Foo {
    case bar(Int?)
    case doo
    static var bar: Foo { .bar(nil) }
    static var baar: Foo { .bar(nil) }
}

let bar = Foo.bar // Swift Compiler Error: Ambigious use of 'bar'
let baar = Foo.baar // No problems
let doo = Foo.doo // No problems

let bar2: Foo = Foo.bar // No problems
@typesanitizer
Copy link

This isn't very different from overloading enum cases (which is deliberately allowed by https://github.com/apple/swift-evolution/blob/master/proposals/0155-normalize-enum-case-representation.md )

enum X {
  case a(Int?)
  case a // OK
}

Keeping up with that, both of the following fail to compile

enum Y {
  case a
  case b
  static var a: Y { .b }
}
enum Z {
  case a
  case a
}

@typesanitizer
Copy link

Marking this as "Invalid" as there's no "Works Correctly" option for the resolution field. (The question itself is a valid one.)

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
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

2 participants