Enum literals, good? bad? what do you think?
Walter Bright
newshound2 at digitalmars.com
Thu Jul 22 17:19:23 UTC 2021
On 7/22/2021 9:16 AM, Steven Schveighoffer wrote:
> ```d
> enum A
> {
> one,
> two,
> three
> }
>
> enum B
> {
> one,
> two,
> three
> }
>
> void foo(A a, B b) {... }
>
> // how to call foo without having to specify `A.one` or `B.one`?
> ```
>
> In Swift, `.symbol` is specifically for type properties, and fit perfectly for
> enums (and other things, see
> [here](https://www.swiftbysundell.com/tips/using-dot-syntax-for-static-properties-and-initializers/)).
How does that interact with function overloading?
I looked at the Swift reference manual
https://docs.swift.org/swift-book/ReferenceManual/Expressions.html and couldn't
find answers there.
Seems to me there'd be a combinatorial explosion as the resolver will have to
re-run the match for all different resolutions for `.identifier`. Even if the
compiler does try them all and find a best match, for the user reading the code
I doubt it would be straightforward to figure out manually which is the right
match. It's already hard enough.
With the alias mixin proposed, the answer is simple. Two different enums in the
same scope with the same member names will cause a compile time error.
More information about the Digitalmars-d
mailing list