Skip to content

AutoValue Builder @This injection fails for certain Builder subtyping #92

@msridhar

Description

@msridhar

Here is a reduced version of a case I see in real code:

class BuilderInheritance {
  abstract static class Base {
    abstract String getProp();
    abstract static class Builder<B extends Builder<?>> {
      abstract B setProp(String value);
    }
  }
  @AutoValue
  abstract static class Sub extends Base {
    static Builder builder() {
      return new AutoValue_BuilderInheritance_Sub.Builder();
    }
    @AutoValue.Builder
    abstract static class Builder extends Base.Builder<Builder> {
      abstract Sub build();
    }
  }
}

The returns receiver checker reports an error for this code, as the generated setProp method for the AutoValue Builder has @This on the return, but the method in the abstract Base.Builder class does not (so it is an invalid override).

I don't know how to automatically fix this case other than looking for all overriding methods in the visitor to decide if @This should be injected. @kelloggm any thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions