Skip to content

Fix S3 dispatch, multi-package loading, and export processing#14

Merged
felix-andreas-finccam merged 1 commit into
mainfrom
claude/project-audit-testing-o63wwp
Jul 3, 2026
Merged

Fix S3 dispatch, multi-package loading, and export processing#14
felix-andreas-finccam merged 1 commit into
mainfrom
claude/project-audit-testing-o63wwp

Conversation

@felix-andreas-finccam

Copy link
Copy Markdown
Contributor

Summary

load_fast() reimplements R's namespace machinery, but several pieces that real packages and multi-package sessions depend on were missing. I reproduced each issue against R, fixed it to mirror base::loadNamespace(), and verified from both the source harness and an installed package namespace.

Bug Symptom before Fix
S3 methods never registered .__S3MethodsTable__. stayed empty; S3 dispatch fell through to *.default / the base method even for print/format, for any method declared with S3method() and not exported by name (the modern default) Call registerS3methods() like loadNamespace(); rebuild the table on incremental reloads so re-sourced methods take effect
lazydata field missing (documented multi-package bug) pkg::name for any name not in exports threw object 'lazydata' not found Seed lazydata + nativeRoutines at namespace creation, matching makeNamespace()
exportPattern() ignored (common trigger for the above) a package using exportPattern("^[^.]") exported nothing, so pkg::fn failed Expand patterns like loadNamespace(), with the internal-name stoplist
exportClasses()/exportMethods() ignored cross-package importClassesFrom() / importMethodsFrom() errored hard Full S4 export processing (class metadata objects + generic method tables, including primitive-generic tables)
.onAttach never run fidelity gap vs devtools::load_all() Run it on full load after attaching to the search path

Tests

  • New S3 fixture in devpackage/ (s3_classes.R + S3method()/export() directives + testthat blocks).
  • New harness coverage: Stage 1 S3 dispatch + table registration, Stage 4m (incremental S3 refresh), .onAttach in Stage 4l, and a new Stage 5 for cross-package fidelity (S3 across packages, exportPattern incl. the . stoplist, exportClasses/exportMethods, pkg:: resolution).
  • Suite: 259 passing, 0 failing (was 230). Package installs cleanly via R CMD INSTALL.

Docs

  • README: removed the now-fixed "known lazydata bug" note, documented S3 + multi-package support.
  • AGENTS.md: added namespace-machinery notes (S3 registration, export processing + stoplist, lazydata, .onAttach) and updated the test-stage/fixture descriptions.
  • TECHNICAL_DEBT.md: recorded the fidelity improvements and the "reload doesn't re-read NAMESPACE" tradeoff.

Notes

  • The incremental path re-sources changed files but does not re-parse NAMESPACE, so adding an export()/S3method()/import still needs full = TRUE (consistent with the existing treatment of imports; documented).

🤖 Generated with Claude Code

https://claude.ai/code/session_0133UhzJyq9xA2BBSA6B1LTd


Generated by Claude Code

load_fast() replicated R's namespace machinery but omitted several
pieces that real packages and multi-package sessions depend on:

- S3 methods declared via S3method() were never registered, so the
  namespace's .__S3MethodsTable__. stayed empty and S3 dispatch fell
  through to *.default / the base method (even for print/format). Now
  calls registerS3methods() like base::loadNamespace(), and rebuilds
  the table on incremental reloads so re-sourced methods take effect.

- The namespace info was missing the `lazydata` field, so `pkg::name`
  for any name not in exports threw "object 'lazydata' not found" (the
  documented multi-package bug). Now seeds `lazydata` and
  `nativeRoutines` at namespace creation, matching makeNamespace().

- Only export() was processed. exportPattern(), exportClasses(), and
  exportMethods() were ignored, so exportPattern packages exported
  nothing (pkg::fn failed) and cross-package importClassesFrom() /
  importMethodsFrom() errored. Now computes exports the way
  loadNamespace() does, including the internal-name stoplist.

- .onAttach was never run. Now runs on full load after attach.

Adds an S3 fixture to devpackage and test stages covering S3 dispatch
(single- and cross-package), incremental S3 refresh, exportPattern /
exportClasses / exportMethods, `::` resolution, and .onAttach.
Suite is 259 passing.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0133UhzJyq9xA2BBSA6B1LTd
@felix-andreas-finccam felix-andreas-finccam merged commit 27a6f03 into main Jul 3, 2026
2 checks passed
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.

2 participants