Skip to content

Type documented R6 fields, S4 slots, S7 properties and method results - #900

Open
renkun-ken wants to merge 7 commits into
codex/roxygen-inherit-paramsfrom
codex/roxygen-class-member-types
Open

renkun-ken wants to merge 7 commits into
codex/roxygen-inherit-paramsfrom
codex/roxygen-class-member-types

Conversation

@renkun-ken

@renkun-ken renkun-ken commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Part 6 of the review split for #894. The base is #899.

This extends explicit parameter and return hints to method declarations and member tags. R6 @field can describe a field or active binding, S4 @slot can refine an ANY slot, and S7 @prop can describe the result of a computed property. A generated S7 constructor can use @param for directly stored properties.

Card <- R6::R6Class("Card", public = list(title = "Atlas"))

Wallet <- R6::R6Class("Wallet", public = list(
  #' @field card (`Card`) The stored card.
  card = NULL
))
wallet <- Wallet$new()
wallet$card <- Card$new()
wallet$card$title  # "Atlas"

#' @slot item (`Card`) The enclosed card.
Sleeve <- methods::setClass("Sleeve", slots = c(item = "ANY"))
Sleeve(item = Card$new())@item$title  # "Atlas"

#' @prop current (`Card`) The displayed card.
Display <- S7::new_class("Display", properties = list(
  entry = S7::class_any,
  current = S7::new_property(getter = function(self) self@entry)
))
Display(entry = Card$new())@current$title  # "Atlas"

An exact S7 method’s known return takes precedence over its generic’s annotation. Inline S4 registration callbacks can use documented formals. The analysis reads active/computed property hints without running getters. General S4 generic return dispatch and detached @R6method blocks remain outside this change.

The S7 class and generic constructors consume scoped hints from the type-hint provider. The provider interprets the roxygen tags, including property precedence and generic parameter and return annotations.

@renkun-ken
renkun-ken added this pull request to stack #909 November 30, 2026 02:07

@eitsupi eitsupi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed by ChatGPT.

The handling of concrete slot and property types, conflicting inherited hints, and computed properties appears appropriate. The additional regression tests for numeric union dispatch also address the interaction with the changes in #896.

One non-blocking architectural concern is the increasing coupling between documentation-derived type information and the inference engine. A clearer separation between type information providers and their consumers would improve maintainability and make it easier to support alternative sources of type information in the future.

No blocking issues found in this PR. Approved.

@renkun-ken
renkun-ken requested a review from eitsupi December 1, 2026 15:58
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