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

Unexpected type.arguments.not.inferred error #6768

Open
msridhar opened this issue Aug 26, 2024 · 3 comments
Open

Unexpected type.arguments.not.inferred error #6768

msridhar opened this issue Aug 26, 2024 · 3 comments
Assignees

Comments

@msridhar
Copy link
Contributor

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?

@msridhar
Copy link
Contributor Author

This is a workaround:

-     return walk.flatMap(
+     return walk.<Foo>flatMap(

@agentgt
Copy link

agentgt commented Sep 5, 2024

@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 #6671 (comment) for that info.

(hopefully the above is helpful and not a distraction).

@msridhar
Copy link
Contributor Author

msridhar commented Oct 2, 2024

Just FYI, I re-tested and this issue remains on 3.48.0.

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

5 participants
@msridhar @agentgt @smillst and others