typetools / typetools/checker-framework

assignment.type.incompatible when using <? extends E> where <E extends @Nullable T>

Open
#3,027 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

This is minimized from the real code (though that link doesn't include the nullness annotations, nor the additional type parameter that causes the problem).

$ cat Caller.java
import org.checkerframework.checker.nullness.qual.Nullable;

class Caller {
  <T, E extends @Nullable T> void foo(Multiset<? extends E> multiset) {
    Entry<? extends E> entry = multiset.someEntry();
  }
}

interface Multiset<E> {
  Entry<E> someEntry();
}

interface Entry<E> {}
$ checker/bin/javac -processor org.checkerframework.checker.nullness.NullnessChecker Caller.java
Caller.java:5: error: [assignment.type.incompatible] incompatible types in assignment.
    Entry<? extends E> entry = multiset.someEntry();
                                                 ^
  found   : @Initialized @NonNull Entry<?[ extends E[ extends T[ extends @Initialized @Nullable Object super @Initialized @Nullable Void] super @Initialized @NonNull Void] super @Initialized @NonNull Void]>
  required: @UnknownInitialization @Nullable Entry<?[ extends E[ extends T[ extends @Initialized @Nullable Object super @Initialized @Nullable Void] super @Initialized @NonNull Void] super @Initialized @NonNull Void]>
1 error

I believe this should be legal: The "found" and "required" are identical if you strip off the first two annotations, and for those annotations, the "found" looks to be a subtype of the "required."

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.

Research direction

Start by reproducing the failure with the provided Caller.java example and the NullnessChecker command. Compare it with the real usage in guava/src/com/google/common/collect/Maps.java around line 585. Done means the generic assignment is accepted without the assignment.type.incompatible error while preserving the nullness checks.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.