Skip to content

fix(checker): keep length(x) on union stub returns like round(x) and cumprod(x) - #910

Merged
sims1253 merged 1 commit into
mainfrom
fix/899-union-arg-length
Nov 13, 2026
Merged

sims1253 merged 1 commit into
mainfrom
fix/899-union-arg-length

Conversation

@sims1253

Copy link
Copy Markdown
Owner

Since #898 vendored r-typeshed c5659cb, round(), cumprod(), sqrt() and the other math stubs return a double | complex union with "length": "arg0". The union return path returned early, before that length was resolved, so round(x) lost length(x) and length checks on the result went silent.

 apply_sig → ReturnSpec::Concrete(c)
   mode = match c.mode
-    union        → return json_rtype_to_rtype(c)   // "arg0" → Length::Unknown
+    union        → union_return = true             // built once the length is known
     double_or_int → integer_or_double = true
   length = resolve c.length (arg0, arg1, longest_arg, ...) + return_length rule
   if integer_or_double → integer_or_double_type(length)
+  if union_return      → json_rtype_with_length(c, length)   // every member gets it

The union is now built the same way as the double_or_int path, after the length spec is resolved. Its members are unchanged. json_rtype_scalar delegates to the new json_rtype_with_length helper.

  • Witness: x <- c(1.4, 2.6); if (round(x) > 1) … and if (cumprod(x) > 1) … were silent on main and now report RY002. R errors on both (the oracle fixture checks this).
  • Still firing: if (x > 1) on the same x (RY002).
  • Still quiet: round(1.4) as a condition (no-diag case).
  • Not covered: round(x, digits), signif() and log(x, base) recycle a longer second argument (length(round(1.234, 1:3)) == 3 in R 4.6.2), and "arg0" doesn't model that. The gap predates chore(typeshed): vendor r-typeshed's GNU R base return contracts (mean, seq, names, table, ...) #898, since the old concrete stub had the same spec. It belongs in r-typeshed.

Proof: ry check on the repro was silent on main and reports RY002 on both cases after the fix. The new type_inference.R cases and the testdata/oracle/union_return_arg_length.R fixture pass (cargo test -p ry-checker --test corpus). The oracle matrix passes 458/459; the one failure, quoted_default_dependencies.R, is environmental (rlang isn't installed locally). ecosystem/run.sh --check reports committed reports current for both packages.txt and posit-packages.txt, so no corpus diagnostic moved and no ledger changes. cargo fmt is clean.

Reviewed with sol-loop: 1 round with gpt-6.1-sol on high. Sol verdict: approved

Closes #899

Claude Opus 5.5 on behalf of Max

A typeshed return with mode "union" returned early, before the call's
length spec was resolved, so round(x) and cumprod(x) lost length(x).
Build the union after the length, like the double_or_int path.

Closes #899
@pullfrog

pullfrog Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

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.

Rate limit reached for requests (429)

Pick another model →

Pullfrog  | Rerun failed job ➔ | View workflow run | via Pullfrog | Using glm-5.3

@coderabbitai

coderabbitai Bot commented Nov 12, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You'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 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: a809851f-2f8b-4671-8577-c60458cc919a
Commits

Reviewing files that changed from the base of the PR and between ff77e45 and d1d4ff1.

Files ignored due to path filters: 1

  • crates/ry-checker/tests/snapshots/corpus__cases_type_inference.snap is excluded by !**/*.snap
Files selected for processing: 5

  • CHANGELOG.md
  • crates/ry-checker/src/infer/construct.rs
  • crates/ry-checker/src/infer/types.rs
  • crates/ry-checker/testdata/cases/type_inference.R
  • crates/ry-checker/testdata/oracle/union_return_arg_length.R
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

🔍 OpenCodeReview found 2 issue(s) in this PR.

  • ✅ Successfully posted inline: 2 comment(s)

@sims1253

Copy link
Copy Markdown
Owner Author

Note

🤖 Claude Opus 5.5 on behalf of Max

No code changes this round. Both OpenCodeReview findings on construct.rs:1092 are declined:

  • Union return skips c.columns: declined. No vendored stub has a "mode": "union" return with columns, and the finding agrees. A column schema on a double | complex union has no meaning. Keeping columns would split the column tail of json_rtype_to_rtype into a new helper, which is extra code for a case no stub has. If a stub ever declares both, the follow-up is to route the union through the same columns code.
  • "Not pinned by any test": incorrect. The PR adds two # expect: RY002 cases to testdata/cases/type_inference.R (round(x) and cumprod(x) on a two-element x) and their snapshot entries in corpus__cases_type_inference.snap. It also adds the must-warn RY002 oracle fixture testdata/oracle/union_return_arg_length.R. On main all three were silent; with the fix they report RY002. A lost arg0 length makes the result unknown-length, so the condition-length check goes silent again and these cases fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Union stub returns drop arg-derived lengths (round(x) loses length(x))

1 participant