Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use type specifiers from signature for function ref resolution, if present. Raise exception if resolution is ambiguous. #1410

Merged
merged 11 commits into from
Sep 16, 2024

Conversation

antvaset
Copy link
Contributor

@antvaset antvaset commented Sep 9, 2024

Closes #1408.

The linked issue is due to the engine not being able to distinguish between two func(List<A>) and func(List<B>) overloads at runtime. At compile time, the functions are resolved correctly, and it's possible to include the disambiguated signatures in the ELM by setting signature level to Overloads or All. If the signatures are present in the ELM, we should therefore use those signatures to resolve function refs at runtime which will fix the issue.

This PR adds support for resolving function refs at runtime using the function ref's signature if the signature is included in the ELM. The changed FunctionRefEvaluator now also throws if it cannot disambiguate between multiple candidate function defs.

Below is an overview of the FunctionRefEvaluator logic before and after the change.

BEFORE: Find the function defs with the matching name and number of operands. If only one function def is found, pick that function def and stop there. If there are multiple candidate function defs, pick the first one with the matching operand types. The Java class types of the function ref's signature (if present, type specifiers are converted to Java classes) or of the evaluated argument expressions are used for comparison. If no function defs are matched in the end, an exception is thrown Could not resolve call to operator 'FUNCTION(ARGUMENT_TYPES)' in library 'LIBRARY_NAME'..

AFTER: Find the function defs with the matching name. If the function ref includes a signature, use the signature to further select the matching function defs (type specifiers are used for comparison). If the function ref doesn't include a signature, the Java class types of the evaluated argument expressions are used for comparison. If no function defs are left in the end, an exception is thrown Could not resolve call to operator 'FUNCTION(ARGUMENT_TYPES)' in library 'LIBRARY_NAME'.. If there are multiple matching function defs, an exception is thrown Ambiguous call to operator 'FUNCTION(ARGUMENT_TYPES)' in library 'LIBRARY_NAME'.. If only one function def is left in the end, pick that function def (normal case).

I am reusing the type specifier comparison implementation from the SimpleElmEvaluator class, which was handy.

Copy link

github-actions bot commented Sep 9, 2024

Formatting check succeeded!

Copy link

codecov bot commented Sep 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 64.20%. Comparing base (3f4aacb) to head (531cabf).
Report is 1 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1410      +/-   ##
============================================
+ Coverage     63.73%   64.20%   +0.47%     
+ Complexity     2666     1867     -799     
============================================
  Files           494      494              
  Lines         27829    27848      +19     
  Branches       5528     5531       +3     
============================================
+ Hits          17737    17880     +143     
+ Misses         7848     7731     -117     
+ Partials       2244     2237       -7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@antvaset antvaset marked this pull request as ready for review September 10, 2024 11:25
@antvaset
Copy link
Contributor Author

Hi @JPercival thanks for the tick! I've pushed some changes to the JaCoCo task so that the coverage of SimpleElmEngine is visible, yet it won't update the bot's comment, so please see the updated report here https://app.codecov.io/gh/cqframework/clinical_quality_language/pull/1410.

@antvaset
Copy link
Contributor Author

Hi @JPercival thanks for the tick! I've pushed some changes to the JaCoCo task so that the coverage of SimpleElmEngine is visible, yet it won't update the bot's comment, so please see the updated report here https://app.codecov.io/gh/cqframework/clinical_quality_language/pull/1410.

Scratch that, it's just updated the comment.

@antvaset antvaset changed the title Resolve function refs using signatures if present Use type specifiers from signature for function ref resolution, if present. Raise exception if resolution is ambiguous. Sep 13, 2024
@brynrhodes brynrhodes merged commit 00dbded into master Sep 16, 2024
5 checks passed
@brynrhodes brynrhodes deleted the resolve-function-refs-using-signatures branch September 16, 2024 20:33
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.

CQL Fluent Functions Overload function name
3 participants