typetools / typetools/checker-framework

False positive with captured wildcards

Open
#6,663 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
1.1k
Forks
440
Avg merge
1d 12h
Merged PRs (30d)
134

Description

Several checkers produce a false positive on the following code.

public class Buggy {

  <A extends FooClass<A>> void use(FooClass<A> fooClass1, FooClass<A> fooClass2) {
    fooClass1.getThenStore().merge(fooClass2.getThenStore());

  }

  interface FooInterface<V extends FooInterface<V>> {}

  interface BarInterface<S extends BarInterface<S>> {}

  static abstract class BarClass<V extends FooClass<V>, S extends BarClass<V, S>> implements
      BarInterface<S> {

    public <S> void merge(S thenStore) {
    }
  }

  static class FooClass<V extends FooClass<V>> implements FooInterface<V> {

    FooInterface<?> a;

    void addStores(FooInterface<?> a) {
      this.a = a;
    }

    @SuppressWarnings("unchecked")
    public <S extends BarClass<V, S>> S getThenStore() {
      return (S) a;
    }
  }
}

/testcases/src/Buggy.java:4: error: [argument] incompatible argument for parameter thenStore of BarClass.merge.
    fooClass1.getThenStore().merge(fooClass2.getThenStore());
                                                         ^
  found   : @UnknownInterned BarClass<A[ extends @UnknownInterned FooClass<A[ extends @UnknownInterned FooClass<A> super @InternedDistinct Void]> super @InternedDistinct Void], capture#01[ extends @UnknownInterned BarClass<A[ extends @UnknownInterned FooClass<A[ extends @UnknownInterned FooClass<A> super @InternedDistinct Void]> super @InternedDistinct Void], capture#01> super @InternedDistinct Void]>
  required: capture#02[ extends @UnknownInterned Object super @InternedDistinct Void]
1 error

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

Reproduce the report using /testcases/src/Buggy.java and inspect the diagnostic at the call to merge. Trace how the checker handles the captured wildcards in this example; done means the reported incompatible-argument error is no longer produced for the shown code while valid checking remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.