Length throws TypeError when its null operand is not an As expression (e.g. an expression reference)
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 65/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript
Research direction
Start with Length.exec in src/elm/overloaded.ts and inspect the translated ELM signature and operand result type mentioned in the issue. Reproduce with the LengthNull examples, checking both expression references and typed null literals. Done when Length(S) returns null and Length(LS) returns 0 without throwing; the issue does not name a test file.
Written by the indexing model from the issue text.
Description
Length throws a TypeError when its argument is null and the operand is not an As expression, for example an expression reference. The typed null literal forms work.
library LengthNull version '1.0.0'
define S: null as String
define LS: null as List<Integer>
define LengthOfNullStringLiteral: Length(null as String) // null
define LengthOfNullStringRef: Length(S) // TypeError
define LengthOfNullListLiteral: Length(null as List<Integer>) // 0
define LengthOfNullListRef: Length(LS) // TypeError
Error for the two failing definitions:
Encountered unexpected error during execution.
Error Message: Cannot read properties of undefined (reading 'type')
CQL Library: LengthNull|1.0.0
Expression: Length
Expected:
Length(S): null, as for a null String (Appendix B; cql-testsLengthNullString);Length(LS): 0, as for a null List (Appendix B; see also #168).
Cause: for a null argument, Length.exec reads this.arg.asTypeSpecifier.type. Only an As operand has asTypeSpecifier; for an ExpressionRef it is undefined:
https://github.com/cqframework/cql-execution/blob/master/src/elm/overloaded.ts#L322
The ELM already carries what is needed to choose the overload. In the translated library above, every Length element has a signature (NamedTypeSpecifier String or ListTypeSpecifier), and the operand has resultTypeName / resultTypeSpecifier. A possible fix is to use the signature or the operand's result type, and not to throw when no type information is present.
Environment:
- cql-execution 3.3.2 and 4.0.0-beta.1 (same line in both);
- ELM from
@cqframework/cql5.8.0 (npm), withEnableResultTypes; - Node 24, Windows 11.
The reference engine has the same pattern: cqframework/clinical_quality_language#1976.
- Dominant language
- JavaScript
- Stars
- 86
- Forks
- 40
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from cqframework/cql-execution
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
cqframework/cql-execution#410 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
cqframework/cql-execution#407 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
cqframework/cql-execution#406 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
cqframework/cql-execution#414 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
cqframework/cql-execution#413 ·
All issues in cqframework/cql-execution
Similar issues
-
Mend: dependency security vulnerability
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
ManageIQ/manageiq-ui-service#2259 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
sagemathinc/sagebrush-agent#230 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
electerious/Ackee#411 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
babalae/bettergi-scripts-list#3905 · 1 comment ·
Maintainers usually reply within 1 day