Skip to content

The purpose of $Hidden union memeber #1178

@timocov

Description

@timocov

Currently for unions (and I guess for enums as well) the codegen generates sealed interface with all variants as sub-classes (records) implementing this sealed interface, which makes the use of such unions type-safe so that's amazing! But what I found a bit interesting is that at least for unions, there is also a private class being created, that is not used anywhere, but it blocks the usage of switch/case on type because the class is hidden and it is not possible to use it in case clause. Can you elaborate what is the purpose of this $Hidden class being generated but not accessible?

Basically for the following smithy model:

structure Payload {
    testUnion: TestUnion
}

union TestUnion {
    first: FirstStruct
    second: SecondStruct
    third: ThirdStruct
}

and the java code:

        switch (input.getPayload().getTestUnion()) {
            case FirstMember fm -> fm.first();
            case SecondMember sm -> sm.second();
            case ThirdMember tm -> tm.third();
            case $Unknown unknown -> {
            }
        }

I'm getting switch' statement does not cover all possible input values error because I didn't cover $Hidden case 🙁

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions