Fix: broaden interval constant-folding to handle As-wrapped literals#1709
Merged
Fix: broaden interval constant-folding to handle As-wrapped literals#1709
Conversation
#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>
Related IssuesThe following open issues may be related to this PR:
|
|
Formatting check succeeded! |
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
Ascastsends) route through a cast+interval conversion chain inconvertExpression, wrapping the Interval inAs(...)before the interval conversion — theexpression is Intervalcheck then fails, falling back to runtime Property extractionunwrapIntervalLiteral()to peek throughAswrappers and find the inner Interval literalconstantFoldIntervalConversion()helper to stay within detekt line limitsTest plan
IntegerIntervalTest ends Interval(null, null)produces constant-folded output matchingIntegerIntervalTest = Interval(null, null)🤖 Generated with Claude Code