Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nullness checker reports 'INFERENCE FAILED' #6346

Closed
cushon opened this issue Dec 8, 2023 · 1 comment
Closed

Nullness checker reports 'INFERENCE FAILED' #6346

cushon opened this issue Dec 8, 2023 · 1 comment

Comments

@cushon
Copy link
Contributor

cushon commented Dec 8, 2023

The nullness checker reports an /*INFERENCE FAILED for:*/ error for the following program.

This may be related to #6071 / #979.

import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.Supplier;

public class X {

  public abstract static class A<X extends A<X, Y>, Y extends A.Builder<X, Y>> extends B<X, Y> {

    public abstract static class Builder<X1 extends A<X1, Y1>, Y1 extends Builder<X1, Y1>>
        extends B.Builder<X1, Y1> {}
  }

  public abstract static class B<X2 extends B<X2, Y2>, Y2 extends B.Builder<X2, Y2>> implements C {

    public abstract static class Builder<X3 extends B<X3, Y3>, Y3 extends Builder<X3, Y3>>
        implements C.Builder {}
  }

  public interface C extends D {
    interface Builder extends D, Cloneable {}
  }

  public interface D {}

  abstract static class E<L extends A<L, ?>, I, O> extends F<L> {

    public abstract static class Builder<L extends A<L, ?>, I, O> {
      public <T> Builder<L, I, O> g(Function<I, T> x, BiConsumer<O, T> y) {
        throw new AssertionError();
      }

      public abstract Builder<L, I, O> version(int version);
    }

    public static <
            L extends A<L, B>,
            B extends A.Builder<L, B>,
            I extends A<I, O>,
            O extends A.Builder<I, O>>
        Builder<L, I, O> f(L x, Function<L, List<I>> y, Supplier<O> z, BiConsumer<B, I> z1) {
      throw new AssertionError();
    }
  }

  public interface G extends D {}

  abstract static class H extends A<H, H.Builder> implements G {

    public List<I> h() {
      throw new AssertionError();
    }

    public static final class Builder extends A.Builder<H, Builder> implements G {

      private Builder i(I value) {
        return this;
      }
    }

    public static H j() {
      throw new AssertionError();
    }
  }

  public interface J extends D {}

  public static final class I extends A<I, I.Builder> implements J {

    public long k() {
      return 0L;
    }

    public static final class Builder extends A.Builder<I, I.Builder> implements J {

      Builder l(long value) {
        return this;
      }
    }

    public static Builder n() {
      throw new AssertionError();
    }
  }

  abstract static class F<L extends A<L, ?>> {}

  void f() {
    var x = E.f(H.j(), H::h, I::n, H.Builder::i).g(I::k, I.Builder::l);
  }
}
./checker-framework-3.41.0/checker/bin/javac -processor nullness X.java
X.java:89: error: [methodref.param] Incompatible parameter type for value
    var x = E.f(H.j(), H::h, I::n, H.Builder::i).g(I::k, I.Builder::l);
                                                         ^
  found   : @Initialized @NonNull long
  required: /*INFERENCE FAILED for:*/ ? extends @Initialized @Nullable Object
  Consequence: method in @Initialized @NonNull Builder
    @Initialized @NonNull Builder l(@Initialized @NonNull Builder this, @Initialized @NonNull long p0)
  is not a valid method reference for method in @Initialized @NonNull BiConsumer<@Initialized @NonNull Builder, /*INFERENCE FAILED for:*/ ? extends @Initialized @Nullable Object>
    @NonNull void accept(@Initialized @NonNull BiConsumer<@Initialized @NonNull Builder, /*INFERENCE FAILED for:*/ ? extends @Initialized @Nullable Object> this, @Initialized @NonNull Builder p0, /*INFERENCE FAILED for:*/ ? extends @Initialized @Nullable Object p1)
1 error
@smillst
Copy link
Member

smillst commented Jan 12, 2024

#979 is now fixed and the fix is in master. This test case now passes. (https://github.com/typetools/checker-framework/blob/master/framework/tests/all-systems/java8inference/Issue6346.java)

@smillst smillst closed this as completed Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants