Skip to content

Address review feedback and add comprehensive tests for typed Data.define#859

Open
julianojulio wants to merge 3 commits intocbothner/typed-data-membersfrom
julianojulio/typed-data-members-review
Open

Address review feedback and add comprehensive tests for typed Data.define#859
julianojulio wants to merge 3 commits intocbothner/typed-data-membersfrom
julianojulio/typed-data-members-review

Conversation

@julianojulio
Copy link
Copy Markdown

Builds on @cbothner's typed Data.define work (sorbet#8079), addressing @jez's review feedback.

Changes

Review feedback (commit 1):

  • Replace opaque pair<MethodDef*, Send*> with named InitializeInfo struct documenting why both fields are needed
  • Add design notes to Data.h covering self.[] (intentionally left untyped) and non-void initialize sig behavior

Comprehensive tests (commit 2):

  • Migration patterns: simple, typed, with methods, with includes
  • Complex types: T.nilable, T.any, T::Array, T::Hash, T::Boolean
  • Single and many (5+) members, nested in modules
  • Malformed sigs: void without params, mismatched keyword names, non-void return
  • Non-trivial initialize: statements before super, no super call, default kwargs
  • Type checking validation: correct types, wrong types, missing kwargs
  • Backward compatibility for untyped Data.define

RBS compatibility (commit 3):

  • Verify that #: RBS comment signatures work identically to sig { } blocks — no Data.cc changes needed

Test plan

All 2250 tests in the full test corpus pass, including 143 rewriter tests.

@julianojulio julianojulio requested a review from cbothner March 11, 2026 15:51
@julianojulio julianojulio force-pushed the julianojulio/typed-data-members-review branch from 40d5298 to 84357c5 Compare March 11, 2026 16:59
Comment thread rewriter/Data.cc
struct InitializeInfo {
// The initialize method definition. Used to check whether its body is bare `super`,
// which is the only case where we can reliably propagate types to attribute readers.
const ast::MethodDef *methodDef;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Who owns these pointers? Please document their lifetime and who is expected to free them

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

added ownership and lifetime docs to the struct comment...

Both are non-owning borrows into the block body's ExpressionPtr tree. No explicit deallocation is needed as the ExpressionPtr destructor handles cleanup when the AST is destroyed.

@julianojulio julianojulio force-pushed the julianojulio/typed-data-members-review branch from 84357c5 to a72838e Compare March 13, 2026 00:37
- Replace opaque pair<MethodDef*, Send*> with named InitializeInfo struct
  that documents why both fields are needed (methodDef for checking bare
  super, sigParams for extracting types)
- Document pointer ownership: non-owning borrows into the block body's
  ExpressionPtr tree, valid until block body is move()'d into the class
  definition, no explicit deallocation needed
- Update Data.h with comprehensive doc comments covering the typed
  Data.define feature and design decisions about self.[] and non-void sigs
Test scenarios covering:
- Migration patterns (simple, typed, with methods, with includes)
- Complex types (T.nilable, T.any, T::Array, T::Hash, T::Boolean)
- Single and many (5+) members, nested in modules
- Malformed sigs: void without params, mismatched keyword names, non-void return
- Non-trivial initialize: statements before super, no super call, defaults
- Type checking validation: correct types, wrong types, missing kwargs
- Backward compatibility for untyped Data.define
Verify that RBS comment signatures (#: syntax) work with typed Data.define
identically to sig { } blocks. The RBS rewriter translates comments into
sig nodes before the Data rewriter runs, so no Data.cc changes are needed.

Excluded from Prism test corpus (same as all other RBS tests).
@julianojulio julianojulio force-pushed the julianojulio/typed-data-members-review branch from a72838e to dbd24d3 Compare March 13, 2026 01:19
@julianojulio
Copy link
Copy Markdown
Author

Hey @cbothner, do you want to incorporate these changes to your PR? I like the more explicit structure from InitializeInfo and the extra set of "weird" and "wacky" Data.define structures like https://github.com/jez asked on his feedback.

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