typetools / typetools/checker-framework
Inference is not able to use return type in @Nullable type inference
Open
@smillst is already working on this.
Since Aug 8, 2024.
False Positive (false warning or imprecision)
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 440
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 134
Description
In this example
@SuppressWarnings("nullity")
class Test {
abstract static class Typed<T> {
abstract T get();
}
<T> Optional<T> method1(Typed<? extends @Nullable T> arg) {
return Optional.ofNullable(arg.get());
}
<T> Optional<T> method2(Typed<? extends @Nullable T> arg) {
return method1(arg);
}
}
compilation fails with error in method2
C:\Projects\pvyscomponents\java\libs\kernel\repository\api\src\main\java\com\provys\repository\Test.java:23:19
java: [return] incompatible types in return.
type of expression: @Initialized @NonNull Optional<T extends @Initialized @NonNull Object>
method return type: @Initialized @NonNull Optional<T extends @Initialized @Nullable Object>
I believe it should compile without warning, as if it used T as type argument in call to method1, all should be fine
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.