Skip to content

Fix type of method references in inference.#7545

Open
smillst wants to merge 8 commits intotypetools:masterfrom
smillst:issue7489
Open

Fix type of method references in inference.#7545
smillst wants to merge 8 commits intotypetools:masterfrom
smillst:issue7489

Conversation

@smillst
Copy link
Member

@smillst smillst commented Mar 11, 2026

Fixes #7489.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 11, 2026

📝 Walkthrough

Walkthrough

The 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

  • Correct inference for method references. #7542: Modifies method-reference type inference logic related to handling inexact/inexact method references, indicating a strong code-level connection to the receiver/method-ref inference changes in InferenceFactory.
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The pull request addresses the core issue by fixing method reference type inference in InferenceFactory, ensuring unbound method references receive correct types, preventing the false bound crash when using Comparator.thenComparing.
Out of Scope Changes check ✅ Passed All changes are directly related to the issue: InferenceFactory fixes the inference bug, FalseBoundException improves error messages, and Issue7489.java provides a regression test matching the reported problem.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between f621ebf and 457753f.

📒 Files selected for processing (3)
  • framework/src/main/java/org/checkerframework/framework/util/typeinference8/types/InferenceFactory.java
  • framework/src/main/java/org/checkerframework/framework/util/typeinference8/util/FalseBoundException.java
  • framework/tests/all-systems/Issue7489.java

mernst
mernst previously approved these changes Mar 12, 2026
Copy link
Member

@mernst mernst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@mernst mernst removed their assignment Mar 12, 2026
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between d809178 and 5c45fef.

📒 Files selected for processing (1)
  • framework/tests/all-systems/Issue7489.java

Comment on lines +6 to +12
// @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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 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:


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.

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

Successfully merging this pull request may close these issues.

[type.argument.inference.crashed] Type argument inference crashed for Comparator.thenComparing

2 participants