Allow abstract methods to be implemented via `method_missing`
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
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.
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.
- Dominant language
- Ruby
- Stars
- 3
- Forks
- 5
- Avg merge
- 8d 23h
- Merged PRs (30d)
- 8
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.
More from Shopify/type_toolkit
-
good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Shopify/type_toolkit#4 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
Shopify/type_toolkit#45 ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
Shopify/type_toolkit#20 ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
Shopify/type_toolkit#14 ·
-
good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 52/100
Shopify/type_toolkit#10 ·
All issues in Shopify/type_toolkit
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
simp/pupmod-simp-simp#395 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
simp/pupmod-simp-rsyslog#219 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
simp/pupmod-simp-pupmod#256 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
simp/pupmod-simp-sudo#150 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100