Skip to content

Resolve "polymorphic method binding"

Fuzz requested to merge 55-polymorphic-method-binding into master

This MR addresses issues we've seen with braid master on cordite regarding overloaded methods. One of the notable cases is the binding to methods that had multiple parameters of complex types.

To address these, the algorithm has been tweaked to generate a proximity score between the request parameter value and a potential target parameter type. In this work, we reprioritise the scoring function such that:

  • we prefer perfect matches between the source and target.
  • with the exception of the source being a String, where we prefer non-String overloads in case of ability to parse the string
  • in jsonrpc all complex types are received as Maps prior to further parsing. If an overload explicitly states that it receives a Map, then clearly the author wishes to handle any potential source type dynamically, and we score this higher than overloads with complex types.
  • we also deprioritize casts that increase precision of values (from say int to long)in favour of a direct match.

Finally, we memoize the inner calculation of a source-target scoring to avoid repeated reflection of duplicate pairings.

Edited by Fuzz

Merge request reports