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

Generic base types cause compile errors #161

Closed
ZacSweers opened this issue Jan 19, 2020 · 1 comment · Fixed by #162
Closed

Generic base types cause compile errors #161

ZacSweers opened this issue Jan 19, 2020 · 1 comment · Fixed by #162
Labels
Milestone

Comments

@ZacSweers
Copy link
Collaborator

The following code will fail to build.

Given a generic base class

public abstract class GenericBase<T> {

  public abstract T generic();

  public abstract static class Builder<T, R extends GenericBase<T>, B extends Builder<T, R, B>> {
    public abstract B generic(T generic);

    protected abstract R autoBuild();
  }
}

And autovalue class that uses it

@JsonClass(generateAdapter = true, generator = "avm")
@AutoValue
public abstract class AddressGenericBase extends GenericBase<Address> {

  public abstract String topLevelNonGeneric();

  @AutoValue.Builder public abstract static class Builder
      extends GenericBase.Builder<Address, AddressGenericBase, Builder> {
    public abstract Builder topLevelNonGeneric(String topLevel);
  }
}

This is due to use not using the propertyTypes() API from extensions, so we try to write type variables rather than their materialized types. The fix is to use the propertyTypes() API for this. Note that we'll need to make a couple adjustments to how builder methods are looked up, as they still try to match based on the return type since they override the source ExecutableElement.

@ZacSweers ZacSweers added the bug label Jan 19, 2020
@ZacSweers ZacSweers added this to the 0.5.0 milestone Jan 19, 2020
@ZacSweers
Copy link
Collaborator Author

ZacSweers commented Jan 19, 2020

I've got a fix for this from auto-value-gson. Will port once #160 is merged. AVG PR rharter/auto-value-gson#241

ZacSweers added a commit that referenced this issue Jan 20, 2020
* Add wildcard test types

* Add WildGenericsTest

* Properly match materialized property types in subclasses of generic types

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

Successfully merging a pull request may close this issue.

1 participant