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

AutoEquatable Error due to changing type access level to public #675

Closed
lordcodes opened this issue Sep 12, 2018 · 0 comments
Closed

AutoEquatable Error due to changing type access level to public #675

lordcodes opened this issue Sep 12, 2018 · 0 comments
Labels

Comments

@lordcodes
Copy link

lordcodes commented Sep 12, 2018

A recent PR changed the access level on the Equatable conformance in AutoEquatable to public.

#616

Before this change, Sourcery was correctly generating Equatable conformances in my project, however, after updating to 0.14.0, which is after this change, it can no longer build the project.

The error given: Function cannot be declared public because its parameter uses an internal type.

This is due to the type that is being used with AutoEquatable is internal.

Was this change to public definitely required, as it is perfectly legal to have an equatable implementation in your type that isn't public.

class MyClass: AutoEquatable {
  let field0: String
  let field1: String
}

Before change
Builds successfully.

extension MyClass: Equatable {}
internal func == (lhs: MyClass, rhs: MyClass) -> Bool {
    guard lhs.field0 == rhs.field0 else { return false }
    guard lhs.field1 == rhs.field1 else { return false }
    return true
}

After change
Fails to build

extension MyClass: Equatable {}
public func == (lhs: MyClass, rhs: MyClass) -> Bool {
    guard lhs.field0 == rhs.field0 else { return false }
    guard lhs.field1 == rhs.field1 else { return false }
    return true
}

Alternative

extension MyClass: Equatable {
   static func == (lhs: MyClass, rhs: MyClass) -> Bool {
        guard lhs.field0 == rhs.field0 else { return false }
        guard lhs.field1 == rhs.field1 else { return false }
        return true
    }
}

This alternative also matches the Equatable docs:
https://developer.apple.com/documentation/swift/equatable

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

No branches or pull requests

2 participants