From 8fb17176cb6b9f1ac7580f359379764da60d3d0b Mon Sep 17 00:00:00 2001 From: Alexander Momchilov Date: Fri, 21 Aug 2026 09:47:49 -0400 Subject: [PATCH] Raise for abstract class methods They're not yet tested, and the implementation is broken (missing `extend TypeToolkit::HasAbstractMethods` on the singleton class). --- lib/type_toolkit/dsl.rb | 4 +++- spec/interface_spec.rb | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/type_toolkit/dsl.rb b/lib/type_toolkit/dsl.rb index 7dd6d98..c346ce0 100644 --- a/lib/type_toolkit/dsl.rb +++ b/lib/type_toolkit/dsl.rb @@ -37,7 +37,9 @@ def abstract(method_name) # # is_singleton_method = true, owner is `Foo.singleton_class` # abstract def self.foo; end # end - method_owner = is_singleton_method ? singleton_class : self #: as Module[top] & HasAbstractMethods + method_owner = is_singleton_method ? raise(NotImplementedError, <<~MSG) : self + Abstract singleton methods are not supported yet. + MSG # Register the fact that this method is meant to be abstract, # used by APIs like `abstract_method_declared?` and `Method#abstract?` diff --git a/spec/interface_spec.rb b/spec/interface_spec.rb index 24ddc54..c52bf23 100644 --- a/spec/interface_spec.rb +++ b/spec/interface_spec.rb @@ -401,5 +401,19 @@ def something_else; end end end end + + describe "Abstract class methods" do + it "are not yet supported" do + test_context = self + + Module.new do + interface! + + test_context.assert_raises(NotImplementedError) do + abstract def self.abstract_class_method; end # rubocop:disable Style/ClassMethodsDefinitions + end + end + end + end end end