Skip to content

fix(r): recognize contains as a class inheritance keyword - #4902

Closed
ayushcodes10 wants to merge 2 commits into
Graphify-Labs:v8from
ayushcodes10:fix-r-contains-inheritance-keyword
Closed

ayushcodes10 wants to merge 2 commits into
Graphify-Labs:v8from
ayushcodes10:fix-r-contains-inheritance-keyword

Conversation

@ayushcodes10

Copy link
Copy Markdown
Contributor

Bug

add_class_members (shared by setClass/setRefClass and R6Class-family class definitions) only ever recognized the key inherit when looking for a class's superclass argument. That's R6Class's own spelling. But setClass and setRefClass (S4/R5 classes) both spell the identical argument contains instead — e.g. Derived <- setRefClass("Derived", contains = "Base", ...). Since only inherit was checked, every S4/R5 inheritance relationship was silently dropped — no inherits edge emitted at all, with no error.

No existing issue or PR covers this; found via self-audit of graphify/extractors/r.py (markdown.py had nothing unclaimed — it's extremely heavily iterated, and every plausible gap checked was already fixed and documented with an issue number). Checked the open R-touching PRs (#2150, #2065 — no overlap; #1759 is a stale, pre-tree-sitter regex-based R extractor proposal that predates and doesn't touch the current implementation) — no overlap.

Fix

Changed the single-key check to a set membership check: if key in {"inherit", "contains"}, reusing the exact same base-name lookup, external-class node creation, and inherits edge emission already in place for inherit. add_class_members is only ever called from the two setClass/setRefClass/R6-constructor call sites, so there's no risk of contains meaning something unrelated elsewhere.

Tests

Added to tests/test_r_extractor.py:

  • test_r_setrefclass_contains_inheritance_is_recognised — regression: a setRefClass that inherits via contains = "Base" now gets its inherits edge.
  • test_r6class_inherit_still_recognised (control): R6Class's own inherit keyword still works unchanged alongside the new contains handling.

Verification

  • Confirmed the bug pre-fix via git show upstream/v8:... swapped into place (restored byte-identical afterward): the regression test fails, the control passes both before and after.
  • Full suite: 2 failed, 9116 passed, 82 skipped, 1 xfailed — the 2 failures are the pre-existing flakes in test_erlang_extractor.py and the skill backtick test, unrelated to this change.
  • python3 -m tools.skillgen --check: check OK: 134 artifact(s) match committed output and expected/.

R6Class spells its superclass argument inherit, but setClass and
setRefClass both spell the identical argument contains instead. Only
inherit was checked, so a setRefClass or setClass that inherits via
contains silently lost its inheritance edge, with no error, since
both class constructor forms are routed through the same member
scanning function.

Recognize contains alongside inherit when looking for a class's
superclass argument, reusing the exact same base name lookup,
external class node creation and inherits edge already in place for
inherit.
Covers a setRefClass that inherits via contains now getting its
inherits edge, plus a control confirming R6Class's own inherit
keyword still works alongside it.
@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Oct 31, 2026
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @ayushcodes10. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic.

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify reviewed this change.

Worth a look — the grounded gate found no coupling regressions or blocking issues, but 1 advisory finding(s) below merit a look before merge.

Not checked: tests were not run; formal verification proved 0 of 1 changed function(s) (1 sampled, not proven).

Formal verification. PR-changed functions: 1/1 verified (0 proven, 1 may-equivalent, 0 distinguished) · 0 not verified.


Graphify review — findings

Fixes missing inheritance edges for S4 and Reference Classes by treating contains like R6's inherit when add_class_members reads a class constructor's arguments, so setRefClass("Derived", contains = "Base") now links Derived to Base. The superclass value still goes through a single-name lookup, so how it handles contains values that aren't one plain class name, such as vectors and "VIRTUAL", is the part to watch. Adds tests covering the setRefClass case and an R6Class control that confirms inherit still works.

Worth a look

  • contains = c(...) vector is not split into individual superclass edges — graphify/extractors/r.py:236 · Escalate · medium
    • NOT verified (no proof, no reproducing execution) — needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 43 functions depend on the 43 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: extract_r() — 9 callers, 7 callees

Verification — 43 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 43 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

1 of 479 test file(s) selected (0%) via static blast radius.

  • tests/test_r_extractor.py — impact, changed-test

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

Formal verification

No difference found (not proven): No behavior difference found in extract\_r (not a proof).

The verifier ran both versions of extract\_r on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

· 1 more finding(s) on lines outside this diff (see the check run).

safishamsi added a commit that referenced this pull request Nov 1, 2026
…for video + extractors

The four @ayushcodes10 extractor fixes (#4902 R, #4900 elixir, #4899 dart,
#4897 fortran) change per-file AST output and are AST-cached; they share
the global 31->32 bump already landed via #4908/#4895. Extend the comment
to credit them, and add the 0.9.100 changelog entries for #4842 and the four.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Landed in v0.9.100, now on PyPI (pip install graphifyy==0.9.100). R setClass/setRefClass contains= inheritance emits an inherits edge. Thanks for the fix, @ayushcodes10.

@safishamsi safishamsi closed this Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants