Skip to content

JSpecify: infer diamond type-argument nullability from constructor arguments without a target type #1633

Description

@msridhar

E.g., for this code:

@NullMarked
public class Test {
  static class Box<T extends @Nullable Object> {
    private final T value;
    Box(T value) {
      this.value = value;
    }
    T get() {
      return value;
    }
  }
  void test() {
    // should report no error
    var inferredFromInitializer = new Box<>(null);
  }
}

We should be able to infer that inferredFromInitializer has type Box<@Nullable Object>; right now we do not. Possibly related to #1532 .

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions