Skip to content

Fix method overload resolution to use parameter types, not just count#173

Closed
Copilot wants to merge 2 commits intooverloadsfrom
copilot/sub-pr-172
Closed

Fix method overload resolution to use parameter types, not just count#173
Copilot wants to merge 2 commits intooverloadsfrom
copilot/sub-pr-172

Conversation

Copy link

Copilot AI commented Mar 10, 2026

When multiple overloaded methods share the same name and parameter count but differ in types, the verifier was selecting the wrong RefinedFunction — applying incorrect refinements to both invocations and return type checks.

Changes

  • Context.java: Added getFunction(name, target, List<CtTypeReference<?>> paramTypes) overload that matches by qualified parameter types, plus argumentTypesMatch helper. Size-based lookup remains as fallback.

  • MethodsFunctionsChecker.java — invocation paths: getInvocationRefinements, getConstructorInvocationRefinements, and searchMethodInLibrary now pass paramTypes (from CtExecutableReference.getParameters()) into checkInvocationRefinements, which uses type-based lookup first.

  • MethodsFunctionsChecker.java — return path: getReturnRefinements was still using size-based lookup; fixed to extract parameter types from method.getParameters() and do type-based lookup with size-based fallback — consistent with the invocation path.

  • Refactor: Extracted extractParameterTypes(List<CtParameter<?>>) helper to eliminate duplicated loop across getReturnRefinements and loadFunctionInfo.

Example

@ExternalRefinementsFor("java.util.concurrent.Semaphore")
public interface DummySemaphoreRefinements {
    void acquire();                                         // 0-arg
    void acquire(@Refinement("_ >= 0") int permits);       // 1-arg int
}

// Previously both resolved to whichever RefinedFunction appeared first
sem.acquire(-1);  // now correctly triggers a refinement error
sem.acquire(1);   // now correctly passes

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…s and extract helper method

Co-authored-by: CatarinaGamboa <52540187+CatarinaGamboa@users.noreply.github.com>
Copy link
Author

Copilot AI commented Mar 10, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.puppycrawl.com
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.24.2/x64/codeql/tools/linux64/java/bin/java /opt/hostedtoolcache/CodeQL/2.24.2/x64/codeql/tools/linux64/java/bin/java -jar /opt/hostedtoolcache/CodeQL/2.24.2/x64/codeql/xml/tools/xml-extractor.jar --fileList=/tmp/codeql-scratch-a6bbd58face529f3/dbs/java/working/files-to-index8962330907671651262.list --sourceArchiveDir=/tmp/codeql-scratch-a6bbd58face529f3/dbs/java/src --outputDir=/tmp/codeql-scratch-a6bbd58face529f3/dbs/java/trap/java (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Fix logic for method overload with different types Fix method overload resolution to use parameter types, not just count Mar 10, 2026
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.

2 participants