typetools / typetools/checker-framework
Method type argument inference and local variable
Open
@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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.