Repository navigation
fix(checker): keep a deep callback nest's return type, so four nested sapply() calls report RY040 again - #912
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 8 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
A callback literal's diagnostic walk now also collects its return type, and higher-order inference uses it instead of a second, discarding walk of the same literal. That second walk was capped at MAX_CLOSURE_DEPTH, so four nested sapply() callbacks lost their type and v + 1L missed RY040. Without the cap it would make every level walk all deeper levels again. walk_stmt now returns a bare expression statement's value, so a body's trailing expression is inferred once. walk_body_returns shares that walk between signature, callback and user-function return inference. Closes #896
22e1914 to
992742c
Compare
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — the full diff on fix/infer-closure-trailing-expr (8 files), tracing the new return-type flow end to end against the old two-walk design.
- Single-walk callback typing (
higher_order.rs):walk_callback_for_diagnosticsnow returnsOption<Option<RType>>andinfer_ho_resultprefers that type over a second, discardingcallback_return_typewalk. The fallback is correctly preserved for pass 2 / discarding contexts and for named (Expr::Ident) callbacks, and fold specs still short-circuit to unknown after the diagnostic walk. - Shared body walk (
infer/mod.rs,collect.rs):walk_stmtreturns a bare trailing expression's value, and the newwalk_body_returnsderives the implicit return from that single walk (trailing_return_typestill handles trailingif/ closure-factory / empty bodies). Signature building, callback diagnostics, andrefine_fn_returnall share it, which is what makes the work linear. - Equivalence verified arm by arm: the unreachable filters,
is_return_callcovering bothreturn``/invisible(types already collected by the walk), dead-code tails, and the%<-%destructure tail all land where the oldtrailing_return_typedid. The literal depth0equals the ambientself.closure_depthat every reachable invocation (the field is only mutated insidewalk_literal_returns, which forcesdiscarding = true), so only the deliberate cap relaxation differs. Skippinginvalidate_ops_environment()` on the callback scope is sound for callbacks, which execute synchronously at the lexical call site — and matches the assumption the diagnostics walk has always made. - Tests and docs: the new linearity shape (
sapplywithiftails), thedeep_callback_nest_keeps_return_typeunit test, the corpus case + snapshot, the R-verifiedmust-flagoracle fixture, and the CHANGELOG entry all pin the fix and its adjacent idioms;block_walkscounting is unchanged by the refactor.
CI on this head is green across test, Oracle (R), ecosystem, the perf gate, and Known-gap budget, which backs the byte-identical-diagnostics and no-ledger-drift claims. (Local cargo test was not possible in this runner: toolchain rustc 1.99.1 vs the workspace's required 1.100, which ry-core genuinely uses.)
glm-5.3 | 𝕏
There was a problem hiding this comment.
✅ No new issues found — the delta is a pure rebase, not a code change.
Reviewed changes — the incremental delta since the prior pullfrog review at 22e1914.
- Rebase onto current
mainonly: the new head992742csits ond634c2a(the merge of #910) instead offf77e452. The tree diff between the two heads is exactly #910's content (infer/construct.rs,infer/types.rs, the union-return cases intestdata/cases/type_inference.R, the newunion_return_arg_length.Roracle fixture) — none of this PR's own files (higher_order.rs,infer/mod.rs,collect.rs,closure_nesting_work.rs) differ between the two heads. - Consequences verified: the corpus case's RY040 moved from line 1504 to 1526 with the file shift, and the snapshot was regenerated accordingly; the new #910 material interleaves cleanly with the added case. CI (test,
Oracle (R), ecosystem, perf gate) is green on the new head.
glm-5.3 | 𝕏

Four nested
sapply()callbacks lost their result type, sov <- sapply(1L, function(a) ... sapply(1L, function(d) "x")); v + 1Lmissed the RY040 that GNU R's "non-numeric argument to binary operator" calls for. Each callback level was walked once for diagnostics and again, discarding, for its return type. #895 had to cap that second walk at three levels to keep the work linear. Now the diagnostic walk returns the literal's type itself, so every level is walked once and the type survives at any depth. A body's trailing expression now comes from its statement walk instead of being inferred a second time.Removing the cap alone is not enough. Each level's diagnostic walk would start a fresh uncapped discarding chain, and that is quadratic:
lapplytook 11, 49 and 119 block walks at depths 2, 4 and 6. The cap stays for discarding walks such as signature building and the user-function fixpoint.Mechanism:
walk_callback_for_diagnosticsandinfer_ho_resultincrates/ry-checker/src/higher_order.rs, pluswalk_body_returnsininfer/mod.rs. Witness that should change: the issue's example (and the same lines inside a function body) now reports RY040. True positive that stays:lapply(x, function(e) "a")[[i]] + 1still reports RY040. Adjacent idiom that stays quiet:closure_depth_cap_falls_back_to_opaque(four trailing-return closures stay opaque).Proof:
closure_nesting_work::deep_callback_nest_keeps_return_typefailed before the fix (got []) and passes after.nested_closure_work_grows_linearly_with_depthpasses, with a newif-tailedsapplyshape. The new oracle fixturedeep_callback_nest_result.R(must-flag) is backed byRscript --vanilla, which errors withnon-numeric argument to binary operator. There is a new case intestdata/cases/type_inference.R. Release binaries, main ff77e45 against this branch: the example goes from silent to RY040. 24-deepsapply/lapplynests check in 0.02 s. JSON diagnostics with--warn allare byte-identical across all 73 ecosystem-cache packages.ecosystem/run.sh --checkpasses for both manifests, so the ledgers are unchanged. Local runs:cargo test -p ry-checker --lib(1064 passed),--test corpus,--test oracle(default gate) andcargo fmt --all -- --check. Not run locally: workspace tests, clippy and the full oracle matrix (CI runs them), and adump-factscomparison.Closes #896
Reviewed with sol-loop: 1 round with gpt-6.1-sol on high. Sol verdict: approved
Claude Opus 5.5 on behalf of Max