Unexpected `type.arguments.not.inferred` error
Test case (reduced from other code):
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
class Walker {
List<Foo> b(Path c, ClassProvider classProvider) {
try (Stream<Path> walk = Files.walk(c)) {
return walk.flatMap(
g -> {
return StreamUtils.optionalToStream(classProvider.provide());
})
.collect(Collectors.toList());
} catch (IOException e) {
throw new IllegalArgumentException();
}
}
abstract static class ClassProvider {
abstract Optional<? extends Foo> provide();
}
static class StreamUtils {
static <M> Stream<M> optionalToStream(Optional<M> n) {
return null;
}
}
static class Foo {}
}
If I run it through the Tainting Checker, I get these errors:
$ checker-framework/checker/bin/javac -processor tainting Walker.java
Walker.java:14: error: [return] incompatible types in return.
return StreamUtils.optionalToStream(classProvider.provide());
^
type of expression: @Tainted Stream<@Tainted Foo>
method return type: @Tainted Stream<? extends capture#01 extends @Tainted Foo>
Walker.java:14: error: [type.arguments.not.inferred] Could not infer type arguments for StreamUtils.optionalToStream
return StreamUtils.optionalToStream(classProvider.provide());
^
unsatisfiable constraint: @Tainted Foo <: capture#01 extends @Tainted Foo
2 errors
I get similar errors with the Called Methods Checker / Resource Leak Checker, but not with the Nullness Checker (I do get the expected nullness error in optionalToStream).
Are these errors expected?
This is a workaround:
- return walk.flatMap(
+ return walk.<Foo>flatMap(
@mernst and @msridhar I had a similar problem in my project as well with witness notation in #6671 .
I tried to setup a project that was not my opensource project to reproduce it but cannot.
See this comment https://github.com/typetools/checker-framework/issues/6671#issuecomment-2272093501 for that info.
(hopefully the above is helpful and not a distraction).
Just FYI, I re-tested and this issue remains on 3.48.0.
This remains an issue on the latest CF master branch (tested with b175894cb5d6e3e85ca560cc313fc127797e2240). FYI @smillst @mernst in case it's relevant to the major release decision