pointfreeco / swift-case-paths

🧰 Case paths extends the key path hierarchy to enum cases.
https://www.pointfree.co/collections/enums-and-structs/case-paths
MIT License
904 stars 105 forks source link

Build fails if enum is defined in a public extension #148

Closed donnywdavis closed 7 months ago

donnywdavis commented 7 months ago

Describe the bug I have an enum that is defined in an extension that is public. The enum inherits the public access modifier from the extension, however, the AllCasePaths struct and allCasePaths properties do not. This causes the build to fail since these two pieces do not have the same access modifier as the enum that is configured with CasePathable.

If I add the public access modifier directly to the enum then everything works as expected. Even if I move the public keyword, we use SwiftFormat, that has a rule that moves that modifier to the extension. We would have to disable that rule to make it work. Would it be possible that this could work in both contexts, or is this a limitation of macros?

// This will fail to compile
public extension ABTest {
    @CasePathable
    enum Identifier {
    }
}

// This will compile without any issues
extension ABTest {
    @CasePathable
    public enum Identifier {
    }
}

Environment

stephencelis commented 7 months ago

Macros cannot see the parent, so we can't extrapolate the public access on the extension, but it does look like we can always apply public to these APIs, even if the container is not. Should be fixed when #149 is merged!

donnywdavis commented 7 months ago

I figured that it might be a limitation of macros. Thank you for still finding a solution. Really enjoying the possibilities that this package has opened up for us. 😃