Skip to content

assignment.type.incompatible only with explicit "extends @Nullable Object" on type parameter #2995

@cpovirk

Description

@cpovirk

I could be confused, but: I would expect class Map<K> and class Map<K extends @Nullable Object> to be equivalent. It appears that they're not. Here's some code that uses the longer version:

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

interface Set<E> {}

class Map<K extends @Nullable Object> {
  Set<K> keySet = new KeySet();

  class KeySet implements Set<K> {}
}

$ checker/bin/javac -processor org.checkerframework.checker.nullness.NullnessChecker Map.java
Map.java:6: error: [assignment.type.incompatible] incompatible types in assignment.
  Set<K> keySet = new KeySet();
                  ^
  found   : @Initialized @NonNull Map<K extends @Initialized @NonNull Object>.@Initialized @NonNull KeySet
  required: @Initialized @NonNull Set<K extends @Initialized @Nullable Object>
1 error

However, if I tweak the class declaration to the "equivalent" shorter version, then the file compiles successfully. That's the behavior I would have expected in either case.

If I suppress the error, the .class files that I get for the long version is almost identical to that for the short version, according to javap -v. The only difference appears to be in the order of the RuntimeVisibleTypeAnnotations.

Source file and -version -verbose -AprintAllQualifiers output attached.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions