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

Union including Any fails to compile #1326

Open
danielrbradley opened this issue Mar 1, 2024 · 0 comments
Open

Union including Any fails to compile #1326

danielrbradley opened this issue Mar 1, 2024 · 0 comments
Labels
area/codegen Code generation impact/accessibility Something that is difficult or impossible for some people to use kind/bug Some behavior is incorrect or out of spec

Comments

@danielrbradley
Copy link
Member

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:

func pickTypeFromUnion(union *schema.UnionType, expr *model.ObjectConsExpression) schema.Type {

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) {
@danielrbradley danielrbradley added kind/bug Some behavior is incorrect or out of spec impact/accessibility Something that is difficult or impossible for some people to use needs-triage Needs attention from the triage team labels Mar 1, 2024
@justinvp justinvp added area/codegen Code generation and removed needs-triage Needs attention from the triage team labels Mar 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/codegen Code generation impact/accessibility Something that is difficult or impossible for some people to use kind/bug Some behavior is incorrect or out of spec
Projects
None yet
Development

No branches or pull requests

2 participants