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

Problems inferring arguments from stream pipelines #6938

Open
jpschewe opened this issue Dec 24, 2024 · 0 comments
Open

Problems inferring arguments from stream pipelines #6938

jpschewe opened this issue Dec 24, 2024 · 0 comments
Assignees

Comments

@jpschewe
Copy link

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)
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