cqframework / cql-engine

Clinical Quality Language Evaluation Engine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Runtime exception when multiple functions have same "let" name

duncand opened this issue · comments

The CQL Engine fails at runtime with a long stack trace ending in java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 when multiple functions are declared having "let" with common names as each other.

Run the following CQL:

define function f1(arg Integer) returns Integer: arg S let x: S return x
define function f2(arg Integer) returns Integer: arg T let x: T return x
define s1: f2(6)
define s2: f1(4)
define s3: f2(9)
define s4: f1(2)

This is the result:

>> Error: Index: 0, Size: 0
>> Error: Index: 0, Size: 0
>> f1 [1:1] Definition successfully validated
>> f2 [2:1] Definition successfully validated
>> s1 [3:1] 6
>> s3 [5:1] 9

Whichever function was executed first, all of its executions succeed, while the function that wasn't executed first, all of its executions fail. If you switch the statements s1 and s2 the results change.

Changing the order of declaration of the functions does not affect the outcome.

The innermost layers of the stack trace for the error are as follows:

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

	at java.util.ArrayList.rangeCheck(ArrayList.java:653)
	at java.util.ArrayList.get(ArrayList.java:429)
	at org.opencds.cqf.cql.execution.Context.resolveAlias(Context.java:592)
	at org.opencds.cqf.cql.elm.execution.AliasRefEvaluator.evaluate(AliasRefEvaluator.java:12)
	at org.opencds.cqf.cql.elm.execution.QueryLetRefEvaluator.evaluate(QueryLetRefEvaluator.java:12)

And then several dozen more layers follow.