Skip to content

[regression fix] Type undocumented module methods from the method they override - #212

Closed
apiology wants to merge 1 commit into
masterfrom
type-module-super-from-including-class
Closed

apiology wants to merge 1 commit into
masterfrom
type-module-super-from-including-class

Conversation

@apiology

Copy link
Copy Markdown
Owner

Claude: This PR was written by Claude Code on behalf of @apiology.

Problem:

An undocumented module method that overrides a documented one loses its type:

class Base
  # @return [Hash]
  def serialize; end
end

class Klass < Base; end

module Mod
  def serialize
    super
  end
end

Klass.include Mod
# inferred: undefined, expected Hash
Klass.new.serialize

Since castwide#1378 maps explicit-receiver includes like solid_queue's ActiveJob::Base.include ActiveJob::BatchId, ActiveJob::Base#serialize now infers undefined instead of Hash{String => undefined}.

Solution:

ApiMap#get_methods gives such a module method the type of the nearest later method of the same name in the including class's ancestry, since the module's own ancestors never contain that method.

It skips a later pin at the same path (the same method from another source) and types with unresolved generics. It works in get_methods rather than get_method_stack because callers such as solargraph-rails' definition specs typify the pins get_methods returns.

Test plan:

An undocumented method in a module, such as solid_queue's
ActiveJob::BatchId#serialize (`super.tap { ... }`), typed as undefined
even when the class including the module inherits a documented method
of the same name. Pin::Method#typify_from_super can only search the
module's own ancestors, which never contain the including class's
superclass, and call inference takes the first pin of the class's
method stack, so `ActiveJob::Base.new.serialize` was undefined too.

castwide#1378 made this visible by mapping explicit-receiver includes such as
`ActiveJob::Base.include ActiveJob::BatchId`, which put BatchId's
method first in ActiveJob::Base's stack; an inline `include` inside the
class body had the same gap before it.

ApiMap#get_methods now gives such a module method the type of the
nearest later method of the same name in the class's ancestry, using
Pin::Base#proxy. It runs in get_methods rather than get_method_stack
because callers like solargraph-rails' definition specs typify the
pins get_methods returns.

A nearest later pin at the same path (the same method from another
source) blocks the proxy: taking an RBS `void` for
SchemaStatements#create_table that way lost the block parameter type
in migrations. A later type with unresolved generics is skipped too,
since another namespace's type parameters leaked into ActiveRecord
finder methods otherwise.
@apiology

Copy link
Copy Markdown
Owner Author

Claude: Closing: failure B (ActiveJob#logger) is fixed by castwide#1446 instead, so this approach is no longer needed.

@apiology apiology closed this Oct 22, 2026
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.

1 participant