Skip to content

Regression from #7007: primitive widening plus the ambiguity check makes any width-differing overload pair unresolvable, so a registered twice(int)/twice(long) can no longer be called #7110

Closed

Description

@ruispereira

Summary

The #7007 fix taught overload dispatch to accept primitive widening. Combined with the ambiguity rejection added in the same change, any pair of overloads differing only in numeric width is now unresolvable: both candidates match after widening, and the call is refused. This is a regression - the pre-fix exact-match dispatch resolved twice(5) fine.

Found during a regression pass over the last two days of engine churn (JavaMethodFunctionDefinition.java was touched 9 times in that window).

Where (HEAD 38034d9c8)

engine/src/main/java/com/arcadedb/function/java/JavaMethodFunctionDefinition.java:285-294, typeMatches:

if (paramType.isPrimitive()) {
  final Class<?> argPrimitiveType = unwrap(arg.getClass());
  return argPrimitiveType != null
      && (argPrimitiveType == paramType || WIDENING_CONVERSIONS.getOrDefault(argPrimitiveType, Set.of()).contains(paramType));
}

and :250-257, which refuses as soon as two candidates match:

for (final Method m : pool) {
  if (acceptsArgumentTypes(m, args)) {
    if (match != null)
      throw ambiguousOverloadException(allCandidates, args);
    match = m;
  }
}

An Integer argument now matches int exactly and long by widening, so both overloads qualify and neither wins. Java's own resolution picks the most specific (int); this picks nothing.

Repro

Verified at 38034d9c8. Register a class whose overloads differ only in width:

public static class Lib {
  public static long twice(long v){ return v*2; }
  public static int  twice(int v){ return v*2; }
  public static String only(String s){ return s+"!"; }
}
db.getSchema().registerFunctionLibrary(
    new JavaClassFunctionLibraryDefinition("t", Lib.class.getName()));
SELECT `t.twice`(5)  -> THREW FunctionExecutionException: Error on executing function
                        'Lib::twice': cannot resolve which overload to call among
                        [public static int Lib.twice(int), public static long Lib.twice(long)]
                        for argument type(s) [java.lang.Integer]
SELECT `t.only`('a') -> {"v":"a!"}     (control: single-candidate dispatch still fine)

Scope - narrower than it looks, and stated deliberately

This does not affect SQL's built-in functions. I checked, because that would have made it severe:

SELECT abs(5)    -> {"v":5}
SELECT abs(-5)   -> {"v":5}
SELECT abs(5.5)  -> {"v":5.5}
SELECT sqrt(4)   -> {"v":2}
SELECT max(1,2)  -> {"v":2}

Those are engine-internal SQL functions and never enter this dispatcher. math.abs is not registered by default either (Unknown function name 'math.abs'), so no standard library is wired through here out of the box.

So the blast radius is: a user who registers their own Java class via JavaClassFunctionLibraryDefinition, where that class has width-differing overloads. Width-differing overloads are an ordinary Java idiom, so this is reachable, but it needs an explicit registration.

Suggested fix

Prefer the most specific applicable candidate instead of refusing when several apply, i.e. resolve in two passes: exact matches first, and only fall back to widening candidates when no exact match exists. That preserves both the #7007 widening behaviour and the pre-fix ability to call twice(5).

Keeping the ambiguity error is right for genuinely ambiguous cases (two unrelated reference types), but an exact match should always beat a widened one - which is what Java itself does.

Note the related interaction: JavaClassFunctionLibraryDefinition keys functions by bare method name, so both overloads land under twice and reach this dispatcher together. That grouping was the #7007 fix's own doing, so the two halves need to be consistent.

Scope / confidence

High - reproduced, with a single-candidate control in the same run and the built-in SQL functions checked to bound the claim.

Activity

  1. added
    engine
    on Sep 3, 2026
  2. added this to the 26.9.1 milestone on Sep 3, 2026
  3. added
    in progress
    on Sep 3, 2026
  4. self-assigned this
    on Sep 3, 2026
  5. added 4 commits that reference this issue on Sep 3, 2026
  6. removed
    in progress
    on Sep 3, 2026
  7. lvca commented on Sep 3, 2026

    @lvca
    Member

    Fixed in #7117 (milestone 26.9.1).

    A Java function library registered with overloads that differ only in numeric width (twice(int) and twice(long)) is callable again. Overload selection now follows the Java rules: the narrowest primitive overload that accepts the argument wins (an exact match over a widened one, long over double), and a call is rejected as ambiguous only when no overload is strictly more specific, exactly as javac resolves it. Overloads that differ in reference types (Object vs String) are still reported as ambiguous.


    ❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugengine

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions