pulumi / pulumi-java

Java support for Pulumi
Apache License 2.0
69 stars 21 forks source link

Union including Any fails to compile #1326

Open danielrbradley opened 6 months ago

danielrbradley commented 6 months ago

When generating a Java SDK with a property whose type is a Union<Any, something>, the builder methods are not compilable due to Java's erasure of generics at runtime.

This could possibly be addressed in this piece of code: https://github.com/pulumi/pulumi-java/blob/f7468e19e755561d2a8770ebcc0374245c424b29/pkg/codegen/java/gen_program_expressions.go#L536

Schema

{
    "types": [
        "aws-native:iottwinmaker:EntityStatus": {
            "properties": {
                "error": {
                    "oneOf": [
                        {
                            "oneOf": [
                                {
                                    "$ref": "pulumi.json#/Any"
                                },
                                {
                                    "$ref": "pulumi.json#/Any"
                                }
                            ]
                        },
                        {
                            "$ref": "#/types/aws-native:iottwinmaker:EntityStatusErrorProperties"
                        }
                    ]
                },
            },
            "type": "object"
        }
    ]
}

Generated code

public final class EntityStatusArgs extends com.pulumi.resources.ResourceArgs {

    @Import(name="error")
    private @Nullable Output<Either<Output<Object>,EntityStatusErrorPropertiesArgs>> error;

    public static final class Builder {

        public Builder error(@Nullable Output<Either<Output<Object>,EntityStatusErrorPropertiesArgs>> error) {
            $.error = error;
            return this;
        }

        public Builder error(Either<Output<Object>,EntityStatusErrorPropertiesArgs> error) {
            return error(Output.of(error));
        }

        public Builder error(Output<Object> error) {
            return error(Either.ofLeft(error));
        }

        public Builder error(EntityStatusErrorPropertiesArgs error) {
            return error(Either.ofRight(error));
        }
    }
}

Compiler error

/home/runner/work/pulumi-aws-native/pulumi-aws-native/sdk/java/src/main/java/com/pulumi/awsnative/iottwinmaker/inputs/EntityStatusArgs.java:69: error: name clash: error(Output<Object>) and error(Output<Either<Output<Object>,EntityStatusErrorPropertiesArgs>>) have the same erasure
        public Builder error(Output<Object> error) {