Repository navigation
fix(checker): stop treating unary + as a no-op, so +TRUE is integer and +"a" errors - #911
Conversation
|
Custom returned an error, so this run stopped. If it names your key, plan or balance, fix that with the provider or pick another model.
|
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
🔍 OpenCodeReview found 1 issue(s) in this PR.
|
d5d4855 to
42b7bd4
Compare
|
Note 🤖 Claude Opus 5.5 on behalf of Max All five OpenCodeReview findings are fixed in 42b7bd4.
Corpus |
|
Custom returned an error, so this run stopped. If it names your key, plan or balance, fix that with the provider or pick another model.
|
|
Note 🤖 Claude Opus 5.5 on behalf of Max Rebased onto main after #912 (both touch |
42b7bd4 to
89365b2
Compare
89365b2 to
af9fc4c
Compare
The parser lowered `+x` to `x`, so every fact about `+x` was the
operand's: `+TRUE` stayed logical, `+factor("a")` an integer factor, and
a project `Ops` method was never consulted. `+"a"`, which R rejects, was
silent.
`UnaryOpKind` gains `Pos` and a `symbol()` helper. Inference sends `+`
down the unary `-` path without negating numeric bounds: logical coerces
to integer, the class stays only when the storage mode stays, an `Ops`
method or `Ops.factor` decides classed operands, and character, raw,
list or function operands report RY020. `numeric_literal` folds `+2` to
2 so RY105/RY107 still see the bound.
Closes #891
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keeping every `+` as `UnaryOpKind::Pos` cost `+`-spelled literals the
proofs a bare literal has: `x[+2]`, `switch(+2L, ...)`, `rep("a", +3)`
and `sum(v, NA) == +1` went opaque, because those recognisers match
only `-literal`. `+2L` is the literal 2L in R (same value and type, and
a classless literal never dispatches `Ops`), so the parser folds `+`
over an integer or double literal as it did before #891. `+TRUE`, `+x`
and calls keep the operator. `numeric_literal` no longer needs a `Pos`
arm.
Also pins the AST shape in a parser test, asserts the RY020 wording for
`+"a"`, and documents `UnaryOpKind::symbol()`.
Refs #891
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
af9fc4c to
6ba4f1b
Compare
| // `+` over a numeric literal is that literal: same value and | ||
| // type, and a classless literal never dispatches `Ops`. Folding | ||
| // it keeps every literal proof `2` has (`x[+2]`, `switch(+2L)`). | ||
| "+" if matches!(expr, Expr::Integer(..) | Expr::Double(..)) => return Some(expr), |
There was a problem hiding this comment.
This parse-time fold erases the `+` node, but in R +2 lowers to the call `+`(2) and evaluation resolves `+` like any other binding — `+` <- function(e1) 0 changes the value of +2 even over a classless literal (this is symbol lookup, independent of the Ops group-generic dispatch the comment cites). The checker models exactly this via operator_rebound/resolves_to_base for unary ops: it still sees -2 (the Neg node is kept) and, after this change, +x (the Pos node is kept), but a rebound `+` is invisible for +2, so the checker proves a numeric literal where R returns the rebound value. Consider either documenting this accepted gap, or leaving the literal fold to the infer layer where operator_rebound(self, "+", scope) can gate it (still emitting the literal proof when `+` resolves to base, like the Neg path does).
Suggestion:
| "+" if matches!(expr, Expr::Integer(..) | Expr::Double(..)) => return Some(expr), | |
| // `+` over a numeric literal is that literal: same value and | |
| // type, and a classless literal never dispatches `Ops`. Folding | |
| // it keeps every literal proof `2` has (`x[+2]`, `switch(+2L)`). | |
| // Accepted gap: a rebound `` `+` `` (`+ <- function(e1) 0`) also | |
| // changes `+2` in R via plain symbol lookup, but only the infer | |
| // layer (`operator_rebound`) can see that; the fold bypasses it. | |
| "+" if matches!(expr, Expr::Integer(..) | Expr::Double(..)) => return Some(expr), |

The parser dropped unary
+, so+xexportedx's type:+TRUEstayed logical,+factor("a")stayed an integer factor, a projectOps.quxwas never asked, and+"a", which R rejects, was silent.+now stays in the AST asUnaryOpKind::Posand takes #890's unary-path. The one exception is+over an integer or double literal, which the parser still folds into the literal: R gives the same value and type, and a classless literal never dispatchesOps. Sox[+2],switch(+2L, ...),rep("a", +3)andsum(v, NA) == +1keep the proofs a bare literal has.UnaryOpKind::symbol()replaces the five copies of the operator-to-string match.On the issue's table,
dump-factsnow gives:+TRUEinteger/no class,+structure(TRUE, class = "foo")integer/no class,+factor("a")logical with RY042,+structure(1, class = "qux")withOps.quxunknown,+structure(1, class = "foo")doublefoo,+Sys.Date()unknown class (the same as #890's-Sys.Date()), and+"a"RY020.-"a"and!"a"still report RY020/RY021.Proof: the new unit test
unary_plus_follows_the_unary_minus_rulefailed before the fix (+TRUEwasLogical) and passes after. It also pins the RY020 wording for+"a". The parser testunary_plus_folds_only_over_numeric_literalspins the AST shape. New fixtures:ry020_unary_plus.R, oracleunary_plus_type_claim.R(R errors on+"a") and facts oraclefacts_ops_unary_plus_class.R(checked against GNU R).dump-factson+1,+2L,v[+2],rep("a", +3)andswitch(+2L, ...)gives exact types and lengths again. Locallycargo test -p ry-checker --test corpus,--test oracle,-p ry-core,-p ry-cli --test e2e facts_oracle -- --include-ignoredandcargo fmt --checkpass, andecosystem/run.sh --checkreports both corpus manifests current, so no ledger changes.Reviewed with sol-loop: 2 rounds with gpt-6.1-sol on high. Sol verdict: approved
Closes #891
Claude Opus 5.5 on behalf of Max
Summary by CodeRabbit
+now follows R’s arithmetic behavior instead of always returning its operand unchanged. Numeric literals retain their existing behavior, while other values are coerced or dispatched according to their type and class.