fix(evaluator): Evaluate same-sheet uncached formula refs (GH-208)#214
fix(evaluator): Evaluate same-sheet uncached formula refs (GH-208)#214
Conversation
Mirror the SheetRef recursive eval pattern in the Ref case so that same-sheet references to Formula(str, None) cells are recursively parsed and evaluated instead of hitting a TypeMismatch error. Add 5 tests: 2-hop chain, 3-hop chain, uncached in arithmetic, cross-sheet→same-sheet chain, and SUM over uncached formulas. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Code Review: PR #214 - Fix Same-Sheet Uncached Formula EvaluationSummaryThis PR successfully mirrors the cross-sheet uncached formula evaluation pattern (from ✅ Strengths1. Code Quality & Consistency
2. Depth Tracking & Cycle Protection
3. Test Coverage (5 new tests)
All test cases follow the repository's pure functional style and use proper assertions. 🔍 Observations & Suggestions1. Circular Reference Test Coverage test("GH-208: detect same-sheet circular uncached reference") {
val sheet = sheetWith(
"Main",
ref"A1" -> CellValue.Formula("B1", None),
ref"B1" -> CellValue.Formula("A1", None)
)
val wb = workbookWith(sheet)
val result = sheet.evaluateFormula("=A1", workbook = Some(wb))
assert(result.isLeft, "Expected cycle detection error")
}2. Performance Consideration (Minor)
Future optimization could consider memoization at the evaluation context level. 3. Documentation // GH-208: Handle same-sheet formula cells without cached values by recursively evaluating
// (mirrors TExpr.SheetRef pattern from GH-161, lines 260-272)🎯 VerdictLGTM with minor suggestions. This is a solid fix that:
The circular reference test suggestion is a nice-to-have for completeness, but not blocking since the protection mechanism is already proven for cross-sheet scenarios. Minor: Test Count DiscrepancyThe PR description mentions "174 evaluator tests" but the repository STATUS.md shows different counts. This is likely just outdated documentation and doesn't affect code quality. Recommendation: Approve and merge after considering the circular reference test addition. Excellent work mirroring the established pattern! 🚀 |
Summary
TExpr.Refcase ofEvaluator.scalaso that same-sheet references toCellValue.Formula(str, None)(uncached) cells are recursively parsed and evaluated instead of failing withTypeMismatch("Numeric", Formula(...))A1=100, B1=A1*2, C1=B1+50where=C1previously erroredTest plan
./mill xl-evaluator.test)./mill __.checkFormat)Closes #208
🤖 Generated with Claude Code