Skip to content

Detect an ambiguous method call - #697

Merged
ggleyzer merged 3 commits into
masterfrom
gene/ambiguos
Oct 15, 2026
Merged

ggleyzer merged 3 commits into
masterfrom
gene/ambiguos

Conversation

@ggleyzer

Copy link
Copy Markdown
Collaborator

Dima reported the issue on Discord when the compiler fails to report an ambiguous call target.

This PR is a fix for the reported issue

@dimitrirakitine dimitrirakitine left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

works as expected now

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

It alters core method-overload resolution exercised by every call site, so potential regressions need human review and a full test-suite run that cannot be verified here.

0 open findings

What changed in this PR

This PR fixes a compiler bug where an ambiguous method call (two overloads that both match a call site exactly, differing only by return type) was silently resolved by picking the first exact match instead of being reported as an error. The fix lives in the core overload-resolution helper collectMatchingMethods, so that all equally-exact candidates are collected and the downstream chooseBest can detect and report the ambiguity as COMPILER-63 (SIGNATURE_AMBIGUOUS).

Changes:

  • In collectMatchingMethods, replaced the "return on first exact match" fast path with a fFoundExact flag: the first exact match clears prior non-exact candidates, subsequent exact matches are also collected, and non-exact matches found afterward are discarded — allowing genuine ambiguity to surface.
  • Fixed per-argument exactness so fExact is accumulated across all arguments (fExact &= …) instead of being overwritten by the last argument's result.
  • Added a negative test (errors.x, expecting COMPILER-63 for var o = f() and f()) and a positive test (misc.x, verifying that return-type context and a void overload still disambiguate correctly).
File Description
javatools/​src/​main/​java/​org/​xvm/​compiler/​ast/​AstNode.java Core fix: collect all exact matches via fFoundExact and accumulate fExact across args so ambiguous calls reach chooseBest.
xdk/​src/​test/​resources/​compiler-errors/​errors.x Negative test asserting COMPILER-63 for unconstrained ambiguous calls.
manualTests/​src/​main/​x/​misc.x Positive test confirming return-type/context and a void overload disambiguate without error.

I traced the change through findMethod → chooseBest and confirmed the collected exact matches correctly produce SIGNATURE_AMBIGUOUS (COMPILER-63) when neither signature is substitutable for the other, while the WithVoid/NonVoid cases remain unambiguous. The fExact &= change is a legitimate correctness fix (previously a later exact argument could wrongly reset an earlier non-exact result). I found no objective defects to flag inline.

One thing I could not verify in this environment (no XDK build / test execution available): because this touches the overload-resolution path exercised by every method call, it could newly surface ambiguity errors in code that previously compiled by arbitrarily picking the first match. That behavioral broadening is the intent, but its repository-wide blast radius warrants running the full manualTests/XDK suite before merge.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@ggleyzer
ggleyzer force-pushed the gene/ambiguos branch 2 times, most recently from fdc1579 to fef1bc4 Compare October 14, 2026 14:08
@ggleyzer
ggleyzer requested a review from lagergren October 14, 2026 17:21

@lagergren lagergren left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved!

The updated fix addresses the three-overload issue I reported. Approved, with two follow-ups:

  1. I took the liberty of adding a regression/coverage test for fExact &= .... A two-argument case where one overload widens the first argument and the other widens the last should report ambiguity. That would catch the previous assignment incorrectly treating the first overload as an exact match.

  2. The generic/concrete example from the earlier review still reports COMPILER-63: String pick(String) alongside <T> T pick(T) remains ambiguous for String text = pick("x"). If this is intentional, please explicitly record that semantic change in the commit message so it is traceable when investigating compiler/LSP behavior.

Add an expected ambiguity diagnostic when two overloads widen different arguments, plus a manual test asserting that a fully exact overload wins. Verify that replacing fExact &= with assignment removes the expected diagnostic.
@ggleyzer

Copy link
Copy Markdown
Collaborator Author

Regarding point 2) - as Cameron wrote earlier:

I could argue/defend either route. Yes, the one with the explicit return value of string is "logically" more specific. But it's still ambiguous since there are two methods that take a string and return a string.

Due to the extremely rare nature of the issue I decided not to chase it any further.

@ggleyzer
ggleyzer merged commit 9174812 into master Oct 15, 2026
5 checks passed
@ggleyzer
ggleyzer deleted the gene/ambiguos branch October 15, 2026 13:23
lagergren added a commit that referenced this pull request Oct 15, 2026
Take rebased #693's AstNode (with #697's ambiguous call detection),
Ecstasy's DirRepository (#701) and the LSP test fork default. Add
#697's regressions to errs' own misc.x and errors.x, keeping the
implicitly abstract class test beside the new ambiguity test.
lagergren added a commit that referenced this pull request Oct 21, 2026
Take rebased #693's AstNode (with #697's ambiguous call detection),
Ecstasy's DirRepository (#701) and the LSP test fork default. Add
#697's regressions to errs' own misc.x and errors.x, keeping the
implicitly abstract class test beside the new ambiguity test.
lagergren added a commit that referenced this pull request Oct 26, 2026
Take rebased #693's AstNode (with #697's ambiguous call detection),
Ecstasy's DirRepository (#701) and the LSP test fork default. Add
#697's regressions to errs' own misc.x and errors.x, keeping the
implicitly abstract class test beside the new ambiguity test.
lagergren added a commit that referenced this pull request Oct 26, 2026
Take rebased #693's AstNode (with #697's ambiguous call detection),
Ecstasy's DirRepository (#701) and the LSP test fork default. Add
implicitly abstract class test beside the new ambiguity test.
lagergren added a commit that referenced this pull request Oct 27, 2026
Take rebased #693's AstNode (with #697's ambiguous call detection),
Ecstasy's DirRepository (#701) and the LSP test fork default. Add
implicitly abstract class test beside the new ambiguity test.
lagergren added a commit that referenced this pull request Oct 28, 2026
Take rebased #693's AstNode (with #697's ambiguous call detection),
Ecstasy's DirRepository (#701) and the LSP test fork default. Add
implicitly abstract class test beside the new ambiguity test.
lagergren added a commit that referenced this pull request Oct 28, 2026
Take rebased #693's AstNode (with #697's ambiguous call detection),
Ecstasy's DirRepository (#701) and the LSP test fork default. Add
implicitly abstract class test beside the new ambiguity test.
lagergren added a commit that referenced this pull request Oct 29, 2026
Take rebased #693's AstNode (with #697's ambiguous call detection),
Ecstasy's DirRepository (#701) and the LSP test fork default. Add
implicitly abstract class test beside the new ambiguity test.
lagergren added a commit that referenced this pull request Oct 29, 2026
Take rebased #693's AstNode (with #697's ambiguous call detection),
Ecstasy's DirRepository (#701) and the LSP test fork default. Add
implicitly abstract class test beside the new ambiguity test.
lagergren added a commit that referenced this pull request Oct 29, 2026
Take rebased #693's AstNode (with #697's ambiguous call detection),
Ecstasy's DirRepository (#701) and the LSP test fork default. Add
implicitly abstract class test beside the new ambiguity test.
lagergren added a commit that referenced this pull request Nov 2, 2026
Take rebased #693's AstNode (with #697's ambiguous call detection),
Ecstasy's DirRepository (#701) and the LSP test fork default. Add
implicitly abstract class test beside the new ambiguity test.
lagergren added a commit that referenced this pull request Nov 4, 2026
Take rebased #693's AstNode (with #697's ambiguous call detection),
Ecstasy's DirRepository (#701) and the LSP test fork default. Add
implicitly abstract class test beside the new ambiguity test.
lagergren added a commit that referenced this pull request Nov 5, 2026
Take rebased #693's AstNode (with #697's ambiguous call detection),
Ecstasy's DirRepository (#701) and the LSP test fork default. Add
implicitly abstract class test beside the new ambiguity test.
lagergren added a commit that referenced this pull request Nov 9, 2026
Take rebased #693's AstNode (with #697's ambiguous call detection),
Ecstasy's DirRepository (#701) and the LSP test fork default. Add
implicitly abstract class test beside the new ambiguity test.
lagergren added a commit that referenced this pull request Nov 11, 2026
Take rebased #693's AstNode (with #697's ambiguous call detection),
Ecstasy's DirRepository (#701) and the LSP test fork default. Add
implicitly abstract class test beside the new ambiguity test.
lagergren added a commit that referenced this pull request Nov 22, 2026
Take rebased #693's AstNode (with #697's ambiguous call detection),
Ecstasy's DirRepository (#701) and the LSP test fork default. Add
implicitly abstract class test beside the new ambiguity test.
lagergren added a commit that referenced this pull request Nov 25, 2026
Take rebased #693's AstNode (with #697's ambiguous call detection),
Ecstasy's DirRepository (#701) and the LSP test fork default. Add
implicitly abstract class test beside the new ambiguity test.
lagergren added a commit that referenced this pull request Nov 25, 2026
Take rebased #693's AstNode (with #697's ambiguous call detection),
Ecstasy's DirRepository (#701) and the LSP test fork default. Add
implicitly abstract class test beside the new ambiguity test.
lagergren added a commit that referenced this pull request Nov 25, 2026
Take rebased #693's AstNode (with #697's ambiguous call detection),
Ecstasy's DirRepository (#701) and the LSP test fork default. Add
implicitly abstract class test beside the new ambiguity test.
lagergren added a commit that referenced this pull request Nov 26, 2026
Take rebased #693's AstNode (with #697's ambiguous call detection),
Ecstasy's DirRepository (#701) and the LSP test fork default. Add
implicitly abstract class test beside the new ambiguity test.
lagergren added a commit that referenced this pull request Nov 26, 2026
Take rebased #693's AstNode (with #697's ambiguous call detection),
Ecstasy's DirRepository (#701) and the LSP test fork default. Add
implicitly abstract class test beside the new ambiguity test.
lagergren added a commit that referenced this pull request Nov 27, 2026
Take rebased #693's AstNode (with #697's ambiguous call detection),
Ecstasy's DirRepository (#701) and the LSP test fork default. Add
implicitly abstract class test beside the new ambiguity test.
lagergren added a commit that referenced this pull request Nov 28, 2026
Take rebased #693's AstNode (with #697's ambiguous call detection),
Ecstasy's DirRepository (#701) and the LSP test fork default. Add
implicitly abstract class test beside the new ambiguity test.
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.

5 participants