Shopify / Shopify/type_toolkit

Allow abstract methods to be implemented via `method_missing`

Open
#11 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

good first issue
Dominant language
Ruby
Stars
3
Forks
5
Avg merge
8d 23h
Merged PRs (30d)
8

Description

In theory: this should be possible:

# typed: true

require "type_toolkit"

module MyInterface
  interface!
  
  #: -> void
  def demo; end
end

class Parent
  def method_missing(m, ...)
    return super unless m == :demo
    
    puts "#demo implemented via #method_missing"
  end
end

class Child < Parent
  # Commenting out this module inclusion makes call succeed
  include MyInterface
end

Child.new.demo

For comparison, Sorbet's static typechecker doesn't allow this, because it doesn't have any way to prove what is or isn't implemented by method_missing. Sorbet runtime raises an error, which can be a change in runtime behaviour (compared to what you would expect without it):

# typed: true

require "sorbet-runtime"

module MyInterface
  extend T::Sig
  extend T::Helpers
  
  interface!
  
  sig { abstract.void }
  def demo; end
end

class Parent
  def method_missing(m, ...)
    return super unless m == :demo
    
    puts "#demo implemented via #method_missing"
  end
end

class Child < Parent
  # Commenting out this module inclusion makes call succeed
  include MyInterface
end

Child.new.demo # (NotImplementedError)
# The method `demo` on MyInterface is declared as `abstract`. It does not have an implementation.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue's MyInterface example with interface!, the abstract demo method, and Parent#method_missing, then trace what happens when Child includes MyInterface. Compare the runtime path with and without the inclusion. Done means an abstract method handled by method_missing can be called without the unexpected NotImplementedError, while unrelated missing methods still behave as shown.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.