Fix type of method references in inference.#7545
Fix type of method references in inference.#7545smillst wants to merge 8 commits intotypetools:masterfrom
Conversation
📝 WalkthroughWalkthroughThe changes modify method-reference type inference, exception messaging, and tests. InferenceFactory: when computing a compile-time declaration type for an unbound method reference and the enclosing type is a declared (non-raw) type, the receiver of the computed compile-time type is updated to that enclosing type. FalseBoundException: if the constraint is a TypeConstraint and has history, that history is appended to the exception message. A new test Issue7489.java is added, defining ClassA, SubClass, and a filter method that maps, sorts with Comparator.comparing().thenComparing(), and collects results. Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@framework/src/main/java/org/checkerframework/framework/util/typeinference8/types/InferenceFactory.java`:
- Around line 792-796: The unconditional receiver override in InferenceFactory
(the block calling compileTimeType.setReceiverType((AnnotatedDeclaredType)
enclosingType) when enclosingType.getKind() == TypeKind.DECLARED) must be
restricted to only unbound member references; change the condition to also check
that memRefKind == MemberReferenceKind.UNBOUND so you only rewrite the receiver
for unbound references. Locate the code in InferenceFactory where
compileTimeType.setReceiverType is called and wrap or extend the if-condition to
include the memRefKind check (referencing memRefKind and
MemberReferenceKind.UNBOUND) to avoid altering receivers for STATIC, NEW, or
BOUND member references.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 3a9985b3-0ec4-499e-b4eb-291eab73c897
📒 Files selected for processing (3)
framework/src/main/java/org/checkerframework/framework/util/typeinference8/types/InferenceFactory.javaframework/src/main/java/org/checkerframework/framework/util/typeinference8/util/FalseBoundException.javaframework/tests/all-systems/Issue7489.java
...src/main/java/org/checkerframework/framework/util/typeinference8/types/InferenceFactory.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@framework/tests/all-systems/Issue7489.java`:
- Around line 6-12: The test's filter method in class Issue7489 uses
Stream.toList() which requires Java 16+, but the file is only skipping below
Java 11; either update the skip directive to "// `@below-java16-jdk-skip-test`" or
change the stream terminal call in Issue7489.filter (the .toList() on the stream
pipeline that maps and sorts SubClass instances) to use
.collect(Collectors.toList()) so the code remains Java 11 compatible; pick one
of these fixes and apply it to the file.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 4695a9a7-4041-4f6f-ab6b-214b16fb0810
📒 Files selected for processing (1)
framework/tests/all-systems/Issue7489.java
| // @below-java11-jdk-skip-test | ||
| public class Issue7489 { | ||
| static List<SubClass> filter(final Collection<ClassA> collection) { | ||
| return collection.stream() | ||
| .map(x -> (SubClass) x) | ||
| .sorted(Comparator.comparing(SubClass::getX).thenComparing(SubClass::getY)) | ||
| .toList(); |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
In which Java version was java.util.stream.Stream#toList introduced, and is it available in JDK 11?
💡 Result:
java.util.stream.Stream#toList was introduced in Java 16. It is not available in JDK 11.
Citations:
- 1: https://bugs.openjdk.org/browse/JDK-8257870
- 2: https://stackoverflow.com/questions/65969919/differences-of-java-16s-stream-tolist-and-stream-collectcollectors-tolist
- 3: https://bugs.openjdk.org/browse/JDK-8256441
- 4: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/stream/Stream.html
Stream.toList() requires Java 16 but test is marked to run on Java 11+.
Line 12 uses Stream.toList(), which was introduced in Java 16. However, line 6 marks the test to skip only below JDK 11, meaning it will attempt to compile on JDK 11–15 and fail.
🔧 Proposed fix
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
+import java.util.stream.Collectors;
@@
return collection.stream()
.map(x -> (SubClass) x)
.sorted(Comparator.comparing(SubClass::getX).thenComparing(SubClass::getY))
- .toList();
+ .collect(Collectors.toList());Either update the skip directive to // @below-java16-jdk-skip-test`` or replace .toList() with `.collect(Collectors.toList())`.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@framework/tests/all-systems/Issue7489.java` around lines 6 - 12, The test's
filter method in class Issue7489 uses Stream.toList() which requires Java 16+,
but the file is only skipping below Java 11; either update the skip directive to
"// `@below-java16-jdk-skip-test`" or change the stream terminal call in
Issue7489.filter (the .toList() on the stream pipeline that maps and sorts
SubClass instances) to use .collect(Collectors.toList()) so the code remains
Java 11 compatible; pick one of these fixes and apply it to the file.
Fixes #7489.