Skip to content

Problems inferring arguments from stream pipelines #6938

Open
@jpschewe

Description

With checker version 3.48.3. Java version 21.0.5. I'm executing the checker org.checkerframework.checker.nullness.NullnessChecker.

Shouldn't NonNull satisfy a PolyNull requirement?

package net.mtu.eggplant.checker;

import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Stream;

import org.checkerframework.checker.nullness.qual.Nullable;

public class StreamTypeArguments {

  static abstract class GoalElement {
    public abstract boolean isGoal();
  }

  static abstract class AbstractGoal extends GoalElement {
    @Override
    public boolean isGoal() { return true; }

    public abstract boolean isComputed();
  }

  static class Goal extends AbstractGoal {
    @Override
    public boolean isComputed() { return false; }

    public boolean isRequired() { return true; }
  }

  static class ComputedGoal extends AbstractGoal {
    @Override
    public boolean isComputed() { return true; }
  }
  
  
  public static void function(final List<GoalElement> goalElements) {

    final boolean somethingRequired = goalElements.stream()//
      .filter(GoalElement::isGoal)//
      .map(AbstractGoal.class::cast)//
      .filter(Predicate.not(AbstractGoal::isComputed)) //
      .map(Goal.class::cast)//
      .anyMatch(Goal::isRequired);
  }
  
  
}
/home/jpschewe/projects/checker-bugs/src/main/java/net/mtu/eggplant/checker/StreamTypeArguments.java:40: error: [type.arguments.not.inferred] Could not infer type arguments for Predicate.not
      .filter(Predicate.not(AbstractGoal::isComputed)) //
                           ^
  unsatisfiable constraint: @Initialized @PolyNull AbstractGoal <: @Initialized @NonNull AbstractGoal
/home/jpschewe/projects/checker-bugs/src/main/java/net/mtu/eggplant/checker/StreamTypeArguments.java:42: error: [methodref.receiver] Incompatible receiver type
      .anyMatch(Goal::isRequired);
                ^
  found   : @Initialized @NonNull Goal
  required: @Initialized @PolyNull Goal
  Consequence: method in @Initialized @NonNull Goal
    @Initialized @NonNull boolean isRequired(@Initialized @NonNull Goal this)
  is not a valid method reference for method in @Initialized @NonNull Predicate<@Initialized @PolyNull Goal>
    @Initialized @NonNull boolean test(@Initialized @NonNull Predicate<@Initialized @PolyNull Goal> this, @Initialized @PolyNull Goal p0)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

    Participants

    @jpschewe@smillst

    Issue actions

      Problems inferring arguments from stream pipelines · Issue #6938 · typetools/checker-framework