Tricky generics + variance case involving wildcards

1 view
Skip to first unread message

Kenneth Knowles

unread,
Mar 11, 2024, 1:36:30 PMMar 11
to Checker Framework discussion
I have a case where I'm not sure how to get the types right, at https://github.com/kennknowles/beam/tree/checker-question

You can repro with:

    git clone https://github.com/kennknowles/beam --branch checker-question
    cd beam
    ./gradlew :sdks:java:core:compileJava

The easier of the two errors is:

    /Redistribute.java:262: error: [type.argument] incompatible type argument for type parameter TransformT of AppliedPTransform.
            AppliedPTransform<?, ?, RedistributeArbitrarily<?>> transform, SdkComponents components) {
                                                           ^
      found   : @Initialized @NonNull RedistributeArbitrarily<? extends @Initialized @Nullable Object>
      required: @Initialized @NonNull PTransform<? extends @Initialized @NonNull Object super capture#0249 extends @Initialized @NonNull PInput, capture#0250 extends @Initialized @NonNull POutput>



So the debugging context is:
  • RedistributeArbitrarily<T> extends PTransform<PCollection<T>, PCollection<T>>
  • PCollection<T> extends both PInput and POutput
  • So mentally I'm rewriting RedistributeArbitrarily<?> to PTransform<PCollection<?>, PCollection<?>> which is certainly PTransform<? extends PInput, ? extends POutput>
The types work with nullness suppressed, and all nullness is default. Any clue where this is going wrong?

So


Reply all
Reply to author
Forward
0 new messages