Skip to content

Fix: broaden interval constant-folding to handle As-wrapped literals#1709

Merged
JPercival merged 1 commit intomainfrom
fix/interval-constant-fold-broadening
Mar 18, 2026
Merged

Fix: broaden interval constant-folding to handle As-wrapped literals#1709
JPercival merged 1 commit intomainfrom
fix/interval-constant-fold-broadening

Conversation

@JPercival
Copy link
Copy Markdown
Contributor

Summary

  • Extends Optimize: constant-fold interval conversions for literal intervals #1707's interval constant-folding optimization to handle Interval literals wrapped in As casts
  • Some operator paths (e.g., ends) route through a cast+interval conversion chain in convertExpression, wrapping the Interval in As(...) before the interval conversion — the expression is Interval check then fails, falling back to runtime Property extraction
  • Adds unwrapIntervalLiteral() to peek through As wrappers and find the inner Interval literal
  • Extracted constantFoldIntervalConversion() helper to stay within detekt line limits

Test plan

  • Full build passes (all existing tests green)
  • Validates that IntegerIntervalTest ends Interval(null, null) produces constant-folded output matching IntegerIntervalTest = Interval(null, null)

🤖 Generated with Claude Code

#1707 constant-folds interval conversions for bare Interval literals,
but some operator paths (e.g., `ends`) route through a cast+interval
conversion chain where convertExpression wraps the Interval in an As
cast before the interval conversion. The `expression is Interval`
check then fails, falling back to runtime Property extraction.

Unwrap As casts to find the inner Interval literal, enabling constant
folding for all operator paths that produce Interval(null, null) or
similar literal interval conversions.

Extracted constantFoldIntervalConversion and unwrapIntervalLiteral
helpers to keep convertIntervalExpression within the detekt line limit.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

Related Issues

The following open issues may be related to this PR:

Issue Title Score Matched Terms
#1133 ToList is not implemented according to the spec 13 operator, property, com, code, null, expression, https, ends, line, test, cqframework (path), java (path), src (path), main (path), org (path), cql (path)
#931 Library XML deserializer doesn't include annotations 12 com, code, through, generated, check, null, https, tests, test, java (path), src (path), library (path), main (path), org (path), cql (path)
#950 Json formatted CQL fails to deserialize via JsonCqlLibraryReader 11.5 chain, property, com, through, fails, generated, https, line, test, cqframework (path), java (path), library (path), org (path), cql (path)
#1505 'Collapse' on at least 2 closed datetime intervals without a high value always fails 11 runtime, before, com, within, fails, interval, null, https, cqframework (path), java (path), src (path), main (path), org (path), cql (path)
#1700 Loading libraries from intermediary forms 10.5 com, within, check, build, null, https, cqframework (path), java (path), src (path), cql2elm (path), kotlin (path), library (path), main (path), org (path), cql (path)

Tip: If this PR addresses any of these issues, please link them using Closes #NNN or Refs #NNN in the PR description.

@github-actions
Copy link
Copy Markdown

Formatting check succeeded!

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 18, 2026

Codecov Report

❌ Patch coverage is 81.25000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.98%. Comparing base (c02ba23) to head (9ff2fe8).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...tlin/org/cqframework/cql/cql2elm/LibraryBuilder.kt 81.25% 0 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               main    #1709   +/-   ##
=========================================
  Coverage     61.97%   61.98%           
- Complexity     3941     3944    +3     
=========================================
  Files           210      210           
  Lines         20378    20383    +5     
  Branches       3882     3884    +2     
=========================================
+ Hits          12630    12634    +4     
  Misses         6139     6139           
- Partials       1609     1610    +1     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@JPercival JPercival merged commit 20b6cd7 into main Mar 18, 2026
9 of 10 checks passed
@JPercival JPercival deleted the fix/interval-constant-fold-broadening branch March 18, 2026 20:47
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.

1 participant