Skip to content

Handle nested restrictive annotations on type variables in @NullUnmarked code #1488

@msridhar

Description

@msridhar
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.NullUnmarked;
import org.jspecify.annotations.Nullable;

@NullMarked
class Test {

  interface Foo<T extends @Nullable Object> {}

  @NullUnmarked
  static <T> T identity(Foo<@NonNull T> t) {
    throw new RuntimeException("not implemented");
  }

  void test(Foo<@Nullable String> s) {
    String x = identity(s); // we should report an error here
  }
}

Right now we do not report an error at the identity call, but we should, since the restrictive @NonNull annotation in the Foo<@NonNull T> parameter type means you cannot pass Foo<@Nullable String>.

Metadata

Metadata

Assignees

No one assigned

    Labels

    jspecifyRelated to support for jspecify standard (see jspecify.dev)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions