typetools / typetools/checker-framework

Method type argument inference and local variable

Open
#2,770 0 comments 0 reactions 1 assignee View on GitHub

@smillst is already working on this.

Since Oct 7, 2019.

False Positive (false warning or imprecision) Java8
Dominant language
Java
Stars
1.1k
Forks
440
Avg merge
1d 12h
Merged PRs (30d)
134

Description

This is probably caused by #979, but the interaction with a local variable seems strange.

Run the Nullness Checker on:

import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

abstract class Demo {
  class Box<R> {}

  abstract <S> S unbox(Box<S> b);

  abstract <T> @NonNull T checkNotNull(@Nullable T sample);
  
  void test(Object s) {}
  
  void bar(Box<?> s) {
    test(checkNotNull(unbox(s)));

    Object o = checkNotNull(unbox(s));
    test(o);
  }
}

The first invocation test(checkNotNull(unbox(s))); type checks.

Putting the argument to test into a local variable causes a argument.type.incompatible error.

The method type argument inference in that case cannot use the assignment context, but should still consider the explicit @NotNull annotation on the checkNotNull return type.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.