alba: bind class_eval'd DSL blocks to T.self_type - #424
Merged
Merged
Conversation
`nested`, `nested_attribute` and `trait` class_eval their block on a subclass of the resource the macro was called on, so `self` inside the block is that resource class — a type the sig can name. `T.untyped` erases it, and with it every `attribute` declared inside the block: a DSL-typing RBI for the resource class no longer applies, so the block parameter and anything derived from it fall back to untyped. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
KaanOzkan
approved these changes
Sep 23, 2026
Contributor
Author
|
Thanks for the quick review and merge! |
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.
Type of Change
Changes
Follow-up to #422, which is mine: I typed the blocks of
nested,nested_attributeandtraitasT.proc.bind(T.untyped). That binding is weaker than the runtime warrants, and the erasure it causes is not local to the block's ownself.All three
class_evalthe block on a subclass of the resource class the macro was called on:So
selfinside the block is exactly the receiver of the macro, whichT.self_typenames precisely. This differs from theActiveSupport::Concerncase in #423: a concern genuinely cannot know its includer, whereas here the type is right there in the call.The cost of
T.untypedis that it also erases what is declared inside the block. A project that types its resources (a Tapioca DSL compiler generating a per-resourceattributesig, or a hand-written shim) loses that typing for everything insidenested do ... end— the block parameter, and every value derived from it, silently becomes untyped, becauseattributeis now being called on an untypedself. In our app this turned a correctT.must(it.price)on aT.nilable(SubscriptionPrice)into a 7050 "redundant T.must", i.e. the annotation did not just fail to add information, it removed information Sorbet previously had. WithT.self_typethat typing is preserved, and inside the block plainnested/attributecalls still resolve throughAlba::Resource::ClassMethodsas before.repo check index,rubocop alba,runtime albaandstatic albaall pass locally.Blocks left alone deliberately:
attribute,meta,on_niland the associationsourceblocks areinstance_exec'd on a resource instance, not the class, soT.self_typewould be wrong there and the honest type is a separate question.🤖 Generated with Claude Code