Skip to content

activesupport: bind ActiveSupport::Concern block DSLs to T.untyped - #423

Merged
amomchilov merged 1 commit into
Shopify:mainfrom
frewsxcv:activesupport-concern-block-binding
Sep 11, 2026
Merged

amomchilov merged 1 commit into
Shopify:mainfrom
frewsxcv:activesupport-concern-block-binding

Conversation

@frewsxcv

@frewsxcv frewsxcv commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Adds annotations for ActiveSupport::Concern#included, #prepended, and #class_methods binding the block's self to T.untyped.

These methods class_eval their block on the including class (or the generated ClassMethods module), so self inside the block is never the concern module. Without a binding, Sorbet types self as T.class_of(TheConcern) and reports 7003 on every DSL call in an included do … end body (scope, validates, has_many, class_attribute, …), which pushes concern modules toward # typed: false.

T.untyped is the honest binding since a concern can't know its includer, and it matches the existing Testing::Declarative#test and SetupAndTeardown#setup/#teardown annotations in this file.

Version guards: class_methods since 4.2, prepended since 6.1.

repo check index, rubocop, runtime activesupport, and static activesupport all pass locally.

`included`, `prepended`, and `class_methods` class_eval their block on
the including class (or the generated ClassMethods module), so `self`
inside the block is never the concern module itself. Without a binding
Sorbet types `self` as `T.class_of(TheConcern)` and reports 7003 for
every DSL call in an `included do … end` body.

`T.untyped` is the honest binding — a concern cannot know its includer —
and matches the existing `Testing::Declarative#test` and
`SetupAndTeardown#setup`/`#teardown` annotations in this file.
@frewsxcv
frewsxcv marked this pull request as ready for review September 11, 2026 19:45
@frewsxcv
frewsxcv requested a review from a team as a code owner September 11, 2026 19:45

@amomchilov amomchilov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Too bad that proc binds can't be generic. T.untyped is the best we can do here, for now.

Thanks!

@frewsxcv

Copy link
Copy Markdown
Contributor Author

@amomchilov Hmm is there something that needs to happen in order for the build in CI to get kicked off?

@amomchilov

Copy link
Copy Markdown
Contributor

@frewsxcv I forgot to push the button :)

Started.

@amomchilov amomchilov added the rbi Change related to RBI annotations label Sep 11, 2026
@amomchilov
amomchilov merged commit 91b5661 into Shopify:main Sep 11, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rbi Change related to RBI annotations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants