typetools / typetools/checker-framework
Problems inferring arguments from stream pipelines
Open
@smillst is already working on this.
Since Dec 26, 2024.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 440
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 134
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)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.