Skip to content

type.argument.type.incompatible sometimes when nested class uses wildcard-parameterized enclosing class #3013

@cpovirk

Description

@cpovirk

I don't know exactly what is required to produce the problem, but I can see it with the following code (minimized from the original error in ImmutableMap):

$ cat MyList.java 
import org.checkerframework.checker.nullness.qual.NonNull;

abstract class MyList<E extends @NonNull Object> {
  static class Nested {
    Nested(MyList<?> list) {
      for (Object o : list.asIterable()) {}
    }
  }

  abstract Iterable<E> asIterable();
}

$ checker/bin/javac -d out -processor org.checkerframework.checker.nullness.NullnessChecker MyList.java 
MyList.java:5: error: [type.argument.type.incompatible] incompatible types in type argument.
    Nested(MyList<?> list) {
                  ^
  found   : ? extends @Initialized @Nullable Object
  required: @Initialized @NonNull Object
1 error

I would expect for MyList<?> to be a valid parameterization (one with behavior equivalent to MyList<? extends @NonNull Object>).

The error goes away if I merely call asIterable (or even assign it to a variable of type Iterable<?>).

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions