fix(cli): Handle qualified ranges in eval sheet inference (GH-210)#217
fix(cli): Handle qualified ranges in eval sheet inference (GH-210)#217
Conversation
containsUnqualifiedCellReferences now checks ArgValue.Range location (Local vs CrossSheet) instead of treating all ranges as unqualified. This fixes eval requiring -s for fully-qualified formulas like =SUM(Revenue!A1:A3). Also replaces wb.sheets.head with headOption pattern match to silence WartRemover warning. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Code ReviewSummaryThis PR correctly fixes a bug in ✅ Strengths1. Correct Logic Implementation (xl-evaluator/src/com/tjclp/xl/formula/graph/DependencyGraph.scala:210-213)
2. Safe WartRemover Compliance (xl-cli/src/com/tjclp/xl/cli/commands/ReadCommands.scala:452-453)
3. Test Coverage
4. Follows Project Standards
💡 Suggestions1. Consider Adding Unit Tests While integration tests pass, consider adding explicit unit tests for // xl-evaluator/test/src/com/tjclp/xl/formula/graph/DependencyGraphSuite.scala
test("containsUnqualifiedCellReferences - CrossSheet ranges are qualified") {
val expr = FormulaParser.parse("=SUM(Revenue!A1:A3)").toOption.get
assert(!DependencyGraph.containsUnqualifiedCellReferences(expr))
}
test("containsUnqualifiedCellReferences - Local ranges are unqualified") {
val expr = FormulaParser.parse("=SUM(A1:A3)").toOption.get
assert(DependencyGraph.containsUnqualifiedCellReferences(expr))
}This would catch regressions more directly than CLI integration tests. 2. Pattern Match Simplification (Optional) The match at DependencyGraph.scala:210-213 could use inline pattern matching: case ArgValue.Range(TExpr.RangeLocation.Local(_)) => true
case ArgValue.Range(TExpr.RangeLocation.CrossSheet(_, _)) => falseCurrent version is fine (perhaps more readable), but this is slightly more concise. 3. Documentation Enhancement Consider updating the docstring for /**
* Check if an expression contains any unqualified cell references that require an ambient sheet
* context.
*
* Unqualified references include:
* - Cell refs: A1, $B$2
* - Range refs: A1:B10
* - Local ranges in function args: SUM(A1:A10)
*
* Qualified references that do NOT require ambient sheet:
* - Sheet-prefixed refs: Revenue!A1
* - Cross-sheet ranges: Revenue!A1:A10
*
* ...🔍 Security & Performance
📋 Checklist
Verdict: ✅ LGTM - Approve with Minor SuggestionsThe fix is correct, safe, and follows XL's rigorous standards. The suggestions above are optional enhancements for future robustness, not blockers for this PR. Great work catching and fixing this quickly after #216! 🎉 |
Summary
containsUnqualifiedCellReferencesnow checksArgValue.Rangelocation (LocalvsCrossSheet) instead of treating all ranges as unqualifiedevalrequiring-sfor fully-qualified formulas like=SUM(Revenue!A1:A3)wb.sheets.headwithheadOptionpattern match to silence WartRemover warningFollow-up to #216 which introduced the method but had a bug in the
ArgValue.Rangecase.Test plan
xl -f test.xlsx eval "=SUM(Revenue!A1:A3)"works without-sflag🤖 Generated with Claude Code