Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Nested buildable types should use the enclosing type's defaults #437

Description

@alicederyn

Default values set on a nested buildable type in the constructor should be ignored when merging, but unfortunately they are currently treated as explicitly-set values, as the merge method in the nested mergeFrom method uses the defaults from its own constructor.

e.g.

@FreeBuilder
interface TypeA {
  int value();  // No default
  class Builder extends TypeA_Builder { }
}

@FreeBuilder
interface TypeB {
  TypeA a();  // Value defaults to 0 on this type
  class Builder extends TypeB_Builder {
    Builder() {
      super().mutateA(a -> a.value(0));
    }
  }
}

TypeB.Builder x = new TypeB.Builder();
TypeB.Builder b = new TypeB.Builder();
b.a().value(10);
b.mergeFrom(x);  // This should not overwrite a.value
y = b.build();
assertEquals(10, y.a()); // Fails

Not sure how to easily fix this — would probably require an API extension, to have the option of passing a different default into the mergeFrom algorithm. It would also break existing code, so probably needs to be a major version bump when fixed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions