Skip to content

JSpecify: infer @Nullable type arguments for type variables from unmarked code #1178

@msridhar

Description

@msridhar

Example:

@NullMarked
class SampleNullUnmarkedCall {

  @NullUnmarked
  static class Foo<T> {
    Foo(T t) {}

    static <U> Foo<U> id(U u) { return new Foo<>(u); }
  }

  static void test() {
    // should report no error
    Foo<@Nullable Object> x = Foo.id(null);
  }
}

Here, since Foo is @NullUnmarked, we can infer @Nullable Object as the type argument for the Foo.id(null) call, even though U (and T) do not have explicit @Nullable upper bounds.

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