StateMachine icon indicating copy to clipboard operation
StateMachine copied to clipboard

`@StateMachineHashable` macro does not account for access control

Open domkm opened this issue 1 year ago • 1 comments

For example, if used on a public enum, it will generate internal enum HashableIdentifier and internal vars hashableIdentifier and associatedValue. This fails to compile.

domkm avatar Jun 26 '24 20:06 domkm

Solution for Problem #61 The code generation template is producing internal declarations for types and members that are associated with public enums. This creates an accessibility level mismatch where public clients attempt to access internal implementation details, violating Swift's access control rules. Apply the @usableFromInline attribute to the internally generated types and members.

public enum YourPublicEnum {
    case caseOne(String)
    case caseTwo(Int)
}

@usableFromInline
internal enum HashableIdentifier {
    case caseOne
    case caseTwo
}

public extension YourPublicEnum {
    @usableFromInline
    internal var hashableIdentifier: HashableIdentifier {
        switch self {
        case .caseOne: return .caseOne
        case .caseTwo: return .caseTwo
        }
    }
    
    @usableFromInline
    internal var associatedValue: Any? {
        // your code
    }
}

I can provide the working code fix ready to merge. Just share the code that's causing the issue, and I'll implement the proper @usableFromInline solution directly. 😊

MohitAnuragi avatar Nov 11 '25 14:11 MohitAnuragi