Address review feedback and add comprehensive tests for typed Data.define#859
Open
julianojulio wants to merge 3 commits intocbothner/typed-data-membersfrom
Open
Address review feedback and add comprehensive tests for typed Data.define#859julianojulio wants to merge 3 commits intocbothner/typed-data-membersfrom
julianojulio wants to merge 3 commits intocbothner/typed-data-membersfrom
Conversation
40d5298 to
84357c5
Compare
amomchilov
reviewed
Mar 12, 2026
| 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; |
There was a problem hiding this comment.
Who owns these pointers? Please document their lifetime and who is expected to free them
Author
There was a problem hiding this comment.
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.
84357c5 to
a72838e
Compare
- 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).
a72838e to
dbd24d3
Compare
amomchilov
approved these changes
Mar 13, 2026
Author
|
Hey @cbothner, do you want to incorporate these changes to your PR? I like the more explicit structure from |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Builds on @cbothner's typed Data.define work (sorbet#8079), addressing @jez's review feedback.
Changes
Review feedback (commit 1):
pair<MethodDef*, Send*>with namedInitializeInfostruct documenting why both fields are neededData.hcoveringself.[](intentionally left untyped) and non-void initialize sig behaviorComprehensive tests (commit 2):
T.nilable,T.any,T::Array,T::Hash,T::BooleanRBS compatibility (commit 3):
#:RBS comment signatures work identically tosig { }blocks — no Data.cc changes neededTest plan
All 2250 tests in the full test corpus pass, including 143 rewriter tests.