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

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

Open
msridhar opened this issue Aug 14, 2019 · 1 comment
Open

Comments

@msridhar
Copy link
Collaborator

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?

@msridhar
Copy link
Collaborator Author

I'll note that for now this can be worked around by adding an @This annotation to Base.Builder.setProp()'s return type. But this weakens our automatic support of AutoValue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant