Shopify / Shopify/type_toolkit
Allow abstract methods to be implemented via `method_missing`
Nobody has claimed this yet.
- 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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