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

comma_inheritance breaks protocol composition in associated types #4027

Closed
2 tasks done
sjmadsen opened this issue Jul 16, 2022 · 3 comments
Closed
2 tasks done

comma_inheritance breaks protocol composition in associated types #4027

sjmadsen opened this issue Jul 16, 2022 · 3 comments
Labels
bug Unexpected and reproducible misbehavior.

Comments

@sjmadsen
Copy link
Contributor

New Issue Checklist

Describe the bug

When two or more protocols are part of a protocol composition on an associated type, changing the & to , can cause a syntax error. For example:

protocol Transformable {
    associatedtype Unit: Equatable & CaseIterable & UnitConvertible

    ...
}

protocol UnitConvertible where Self: Equatable {
    ...
}

When using , instead of &, compilation results in Redundant conformance constraint 'Self.Unit' : 'Equatable'. In this example, it is important that the associated type Unit is declared as the composition of Equatable, CaseIterable, and UnitConvertible.

Complete output when running SwiftLint, including the stack trace and command used

n/a - SwiftLint runs fine. It's just too eager about suggesting that all & be changed to , in protocol compositions. Since it's in the default rule set, swiftlint lint --fix can introduce syntax errors.

Environment

  • SwiftLint version (run swiftlint version to be sure)? 0.47.1
  • Installation method used (Homebrew, CocoaPods, building from source, etc)? Homebrew
  • Paste your configuration file:
opt_in_rules:
  - closure_end_indentation
  - contains_over_first_not_nil
  - empty_count
  - empty_string
  - first_where
  - implicit_return
  - modifier_order
  - nimble_operator
  - operator_usage_whitespace
  - overridden_super_call
  - prefer_nimble
  - prohibited_super_call
  - sorted_first_last
  - trailing_closure
  - unused_import
disabled_rules:
  - identifier_name
  - private_over_fileprivate
  - type_name
inclusive_language:
  override_terms:
    - blacklist
    - whitelist
    - slave
line_length:
  warning: 300
  error: 400
nesting:
  type_level:
    warning: 2
type_body_length:
  warning: 220
  • Are you using nested configurations? Yes, but not applicable to this problem.
    If so, paste their relative paths and respective contents.
  • Which Xcode version are you using (check xcodebuild -version)? 13.4.0
  • Do you have a sample that shows the issue? Run echo "[string here]" | swiftlint lint --no-cache --use-stdin --enable-all-rules
    to quickly test if your example is really demonstrating the issue. If your example is more
    complex, you can use swiftlint lint --path [file here] --no-cache --enable-all-rules.
@marcelofabri
Copy link
Collaborator

It's unfortunate that Swift doesn't treat both in the same way - we probably should file an issue in their GitHub about it. However, I don't think there's much we can do from SwiftLint's side here without moving this to be an analyzer rule (which would make it require a full compilation, besides being much slower).

@sjmadsen
Copy link
Contributor Author

At a minimum, the autocorrect should be turned off. A slightly more aggressive fix is removing it from the default rule set.

@marcelofabri
Copy link
Collaborator

Feel free to put up a PR disabling autocorrect!

@SimplyDanny SimplyDanny added the bug Unexpected and reproducible misbehavior. label Jul 29, 2022
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

No branches or pull requests

3 participants