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

[Rule Request]: Duplicate Enum Cases #2676

Closed
xavierLowmiller opened this issue Mar 10, 2019 · 3 comments

Comments

Projects
None yet
3 participants
@xavierLowmiller
Copy link
Contributor

commented Mar 10, 2019

New Issue Checklist

New rule request

In Swift, it's currently legal to define two identical enum cases as long as the label of an associated value is different:

// This compiles
enum PictureImport {
    case add(image: UIImage)
    case add(data: Data)
}

This, however, leads to compiler errors when switching:

// This doesn't compile
func importImage(_ importedImage: PictureImport) {
    switch importedImage {
    case .add(image: let image): // Error: Tuple pattern element label 'image' must be 'data'
        // ...
    case .add(data: let data):
        // ...
    }
}

I'd like to propose a rule that warns against identical enum case names.

Triggers:

enum PictureImport {
    case add(image: UIImage)
    case add(data: Data)
}

Does Not Trigger:

enum PictureImport {
    case addImage(UIImage)
    case addData(Data)
}

In my opinion, this rule should be enabled by default and be marked as an error.

@jpsim

This comment has been minimized.

Copy link
Collaborator

commented Mar 11, 2019

I’m in favor of adding this as a rule.

However, this looks like it might be a Swift bug. Have you reported this at bugs.swift.org?

@xavierLowmiller

This comment has been minimized.

Copy link
Contributor Author

commented Mar 11, 2019

Not yet, but I just did: https://bugs.swift.org/browse/SR-10077

Let's see what they have to say.

@jpsim

This comment has been minimized.

Copy link
Collaborator

commented Mar 11, 2019

Thanks for filing that! Curious to see what Swift folks say.

marcelofabri added a commit that referenced this issue Jun 2, 2019

marcelofabri added a commit that referenced this issue Jun 2, 2019

marcelofabri added a commit to marcelofabri/SwiftLint that referenced this issue Jun 2, 2019

marcelofabri added a commit to marcelofabri/SwiftLint that referenced this issue Jun 2, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.