Skip to content

Compilation error in 2.11.5 with Comparable & Generics #1603

@wjglerum

Description

@wjglerum

After updating from 2.11.4 to 2.11.5 we had a few compilation errors in the generated code with immutables.

For example consider this report aggregate which has a generic type that should be comparable.

@Value.Immutable
@Value.Style(stagedBuilder = true)
public interface AggregateReport<T extends Comparable<? super T>> extends Comparable<AggregateReport<T>> {

    T aggregationKey();

    BigDecimal valueA();

    BigDecimal valueB();

    BigDecimal valueC();

    @Override
    default int compareTo(AggregateReport<T> other) {
        return aggregationKey().compareTo(other.aggregationKey());
    }
}

It will now result in a compilation error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.14.1:compile (default-compile) on project immutables-samples: Compilation failure: Compilation failure: 
[ERROR] /Users/wjglerum/Dev/immutables-samples/target/generated-sources/annotations/org/acme/ImmutableAggregateReport.java:[328,99] > or ',' expected
[ERROR] /Users/wjglerum/Dev/immutables-samples/target/generated-sources/annotations/org/acme/ImmutableAggregateReport.java:[328,118] <identifier> expected
[ERROR] /Users/wjglerum/Dev/immutables-samples/target/generated-sources/annotations/org/acme/ImmutableAggregateReport.java:[328,127] <identifier> expected
[ERROR] -> [Help 1]

And if I look at the generated code it generated the following build stage:

  @Generated(from = "AggregateReport", generator = "Immutables")
  public interface AggregationKeyBuildStage<T extends Comparable<? super T>> extends BuildStart<T extends Comparable<? super T>> {}

Which ofcourse doesn't compile, and Im not sure what it should be.

For reference, this is what's generated with immutables version 2.11.4:

  @Generated(from = "AggregateReport", generator = "Immutables")
  public interface AggregationKeyBuildStage<T extends Comparable<? super T>> {
    /**
     * Initializes the value for the {@link AggregateReport#aggregationKey() aggregationKey} attribute.
     * @param aggregationKey The value for aggregationKey 
     * @return {@code this} builder for use in a chained invocation
     */
    ValueABuildStage<T> aggregationKey(T aggregationKey);
  }

If I disable staged builders it works again, or if I disable the new option additionalStrictContainerConstructor it also compiles again on 2.11.5

Not sure what should be changed, but happy to dig a bit deeper or try some more things.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions