FirelyTeam / firely-cql-sdk

BSD 3-Clause "New" or "Revised" License
28 stars 16 forks source link

Fix forward references in ExpressionBuilder #437

Closed ewoutkramer closed 1 month ago

ewoutkramer commented 1 month ago

Fixes #397. Fixes #410.

This PR enables the translation of FunctionRef/ExpressionRef to rely on the ref's resultTypeSpecifier instead of having to look the definition up in the DefinitionDictionary. Not using the DefinitionDictionary avoids running into the situation where the ref is a forwards reference whereby the DefinitionDictionary does not yet contain the translated function we want to call.

This PR uses the recent functionality added to LibrarySet to lookup a symbol, and expands this to be able to lookup functions by signature. Given the function name in the FUnctionRef/ExpressionRef, and, in the case of an overload, the signature, we can now lookup any function defined in any library in the LibrarySet, so we can copy over the resultTypeSpecifier.

Filling out this resultTypeSpecifier is now done in a pre-processing step, happening when we are constructing the LibrarySet. The pre-processing step will find all Refs, and then do this:

Otherwise, we cannot find the overload, and we will raise an error. This ensures that after the pre-processor has run, all Refs have a resultTypeSpecifier, and we can depend on that fact.

This PR re-uses the OverloadedFunctionDefinition, and there are some updates to the CanCombine function to make sure the pre-processor fix and the CanCombine use the same criteria.

I also added a bunch of useful extension methods for working with the Elm function elements and signatures.

EvanMachusak commented 1 month ago

I've identified a small issue where we are creating empty ExpressionRef nodes for Retireve.context for statements that are in context Unfiltered and this is causing exceptions during the preprocessing phase. I will fix it.

baseTwo commented 1 month ago

@EvanMachusak, none of the demo projects are able to rebuild as a result of the additional commits. Could you please have a look? Issue #450

baseTwo commented 1 month ago

I'm going to revert the entire previous PR #437. This means the related issues (#397, #410, #442 and #443 ) will be undone and moved back to TODO.

baseTwo commented 3 weeks ago

@ewoutkramer I tried to duplicate the work into a new PR, but still getting stuck https://github.com/FirelyTeam/firely-cql-sdk/pull/468