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

syntactic_sugar incorrectly warns about syntactic sugar on arrays when accessing associated type #3502

Closed
mdznr opened this issue Jan 22, 2021 · 2 comments · Fixed by #3970
Closed
Labels
bug Unexpected and reproducible misbehavior.

Comments

@mdznr
Copy link

mdznr commented Jan 22, 2021

When using syntactic_sugar, it appears to incorrectly warn about something like:

extension Sequence where Element: Collection {
  func foo() -> [Array<Element.Element>.Index] {
    var indices = [Array<Element.Element>.Index]() // ⚠️ Syntactic Sugar Violation: Shorthand syntactic sugar should be used, i.e. [Int] instead of Array<Int>. (syntactic_sugar)
    return indices
  }
}

However, Swift (5.3.2) won’t let you write what SwiftLint is suggesting in this case:

extension Sequence where Element: Collection {
  func foo() -> [Array<Element.Element>.Index] {
    var indices = [[Element.Element].Index]() // 🛑 Cannot call value of non-function type '[Array<Self.Element.Element>.Index.Type]' (aka 'Array<Int.Type>')
    return indices
  }
}

SwiftLint v0.34.0

@personalnadir
Copy link

I think I'm seeing the same issue when accessing the Element typealias in dictionaries - I get the syntactic sugar warning, but using it causes a compile error. However it only occurs in the context of a closure for example:

dictionary.reduce(0, {(count: Int, element: Dictionary<String, Any>.Element) -> Int in
            if let subdictionary = element.value as? [String: Any] {
                return subdictionary["field"] != nil ? count + 1 : count
            }

            return count
        })

@SimplyDanny SimplyDanny added the bug Unexpected and reproducible misbehavior. label May 1, 2022
@SimplyDanny
Copy link
Collaborator

@PaulTaykalo, this might be something for you. 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected and reproducible misbehavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants