checker-framework icon indicating copy to clipboard operation
checker-framework copied to clipboard

type.argument warning when assigning to explicitly retyped type with wildcard parameters

Open MichalStehlikCz opened this issue 4 months ago • 2 comments

using checker 3.49.5

Following code

public class Test<T, L extends List<@Nullable T>> {

  void method(Object x) {
    Test<?, ?> y = (Test<?, ?>) x;
  }
}

produces warning

java: [type.argument] incompatible type argument for type parameter L of Test.
  found   : capture#01[ extends @Initialized @NonNull List<capture#02[ extends @Initialized @Nullable Object super @Initialized @NonNull Void]> super @Initialized @NonNull Void]
  required: @Initialized @NonNull List<capture#02[ extends @Initialized @Nullable Object super @Initialized @Nullable Void]>

I believe there is no reason for warning

MichalStehlikCz avatar Aug 20 '25 13:08 MichalStehlikCz

Any idea how I can workaround this? I have the problem on a field declaration e.g.

class Main {
  List<MyClass<?, ?>> list;
}

class MyClass<X, Y extends X> {}

It fails compilation with the same error as above

error: [type.argument] incompatible type argument for type parameter Y of MyClass.
        private List<MyClass<?,?>> treats;
                               ^
  found   : @Initialized @NonNull Object
  required: capture#07 extends @Initialized @Nullable Object

beikov avatar Oct 28 '25 16:10 beikov

This a bug, but it is not related to #7346 .

smillst avatar Oct 31 '25 17:10 smillst