typetools / checker-framework

Pluggable type-checking for Java
http://checkerframework.org/
Other
1.03k stars 355 forks source link

expression.unparsable in stream created from value set #6750

Open MichalStehlikCz opened 3 months ago

MichalStehlikCz commented 3 months ago
public record Test(
      String type) {

  void test(List<Test> externals) {
    externals.stream()
        .collect(Collectors.groupingBy(Test::type))
        .entrySet()
        .stream()
        .forEach(values -> {
          throw new RegularException("KER_SERVERAPI_DUPLICATE_EID_TYPE",
              "Duplicate external ID type");
        });
  }

}

Compilation fails with

C:\Projects\pvyscomponents\java\libs\kernel\repository\api\src\main\java\com\provys\repository\Test.java:21:18
java: [expression.unparsable] Expression invalid in dependent type annotation: [error for expression: externals.stream().collect(java.util.stream.Collectors.groupingBy(Test::type)); error: Invalid 'Test::type' because class org.checkerframework.com.github.javaparser.ast.expr.MethodReferenceExpr is not a supported expression]
C:\Projects\pvyscomponents\java\libs\kernel\repository\api\src\main\java\com\provys\repository\Test.java:21:18
java: [lambda.param] incompatible parameter types for parameter 0 in lambda expression.
  function parameter type: Entry<capture#01 extends @KeyFor("externals.stream().collect(java.util.stream.Collectors.groupingBy(Test::type))") Object super @KeyFor("externals.stream().collect(java.util.stream.Collectors.groupingBy(Test::type))") String, List<Test>>
  lambda parameter type  : Entry<capture#01 extends @KeyFor("[error for expression: externals.stream().collect(java.util.stream.Collectors.groupingBy(Test::type)); error: Invalid 'Test::type' because class org.checkerframework.com.github.javaparser.ast.expr.MethodReferenceExpr is not a supported expression]") Object super @KeyFor("[error for expression: externals.stream().collect(java.util.stream.Collectors.groupingBy(Test::type)); error: Invalid 'Test::type' because class org.checkerframework.com.github.javaparser.ast.expr.MethodReferenceExpr is not a supported expression]") String, List<Test>>

expression.unparsable seems like caught internal error.

Unlike other recently reported problems, it is probably something older as expression.unparsable has been suppressed in our code even before 3.42.0 and I only noticed it after upgarde to 3.46.0 because lambda.param appeared

smillst commented 3 months ago

The parse error is: MethodReferenceExpr is not a supported expression, which is legitimate, but inference should just infer @UnknownKeyFor instead of an annotation with a parse error.