From 1fb2a10dba67af58a6dba01e3e052662f1ac0b5d Mon Sep 17 00:00:00 2001 From: Takumi Shotoku Date: Fri, 10 Apr 2026 19:21:44 +0900 Subject: [PATCH 1/2] Fix NoMethodError in SigTySingletonNode#show due to uninitialized @args SigTySingletonNode#initialize did not initialize @args, causing a NoMethodError when #show was called during return type checking. This occurred when a method annotated with singleton(X) returned a mismatched type. --- lib/typeprof/core/ast/sig_type.rb | 1 + scenario/regressions/singleton-show-nil-args.rb | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 scenario/regressions/singleton-show-nil-args.rb diff --git a/lib/typeprof/core/ast/sig_type.rb b/lib/typeprof/core/ast/sig_type.rb index cca910ac..87faf355 100644 --- a/lib/typeprof/core/ast/sig_type.rb +++ b/lib/typeprof/core/ast/sig_type.rb @@ -550,6 +550,7 @@ def initialize(raw_decl, lenv) name = raw_decl.name @cpath = name.namespace.path + [name.name] @toplevel = name.namespace.absolute? + @args = raw_decl.args.map {|arg| AST.create_rbs_type(arg, lenv) } end attr_reader :cpath, :toplevel diff --git a/scenario/regressions/singleton-show-nil-args.rb b/scenario/regressions/singleton-show-nil-args.rb new file mode 100644 index 00000000..f196896c --- /dev/null +++ b/scenario/regressions/singleton-show-nil-args.rb @@ -0,0 +1,11 @@ +## update +class Foo +end + +#: -> singleton(Foo) +def test + 1 +end + +## diagnostics +(6,2)-(6,3): expected: singleton(::Foo); actual: Integer From db3869a43acba88a749b7b2278c3861237aa2253 Mon Sep 17 00:00:00 2001 From: Takumi Shotoku Date: Sat, 18 Apr 2026 10:55:32 +0900 Subject: [PATCH 2/2] Support RBS 3.x by guarding ClassSingleton#args with respond_to? --- lib/typeprof/core/ast/sig_type.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/typeprof/core/ast/sig_type.rb b/lib/typeprof/core/ast/sig_type.rb index 87faf355..362adbbc 100644 --- a/lib/typeprof/core/ast/sig_type.rb +++ b/lib/typeprof/core/ast/sig_type.rb @@ -550,7 +550,8 @@ def initialize(raw_decl, lenv) name = raw_decl.name @cpath = name.namespace.path + [name.name] @toplevel = name.namespace.absolute? - @args = raw_decl.args.map {|arg| AST.create_rbs_type(arg, lenv) } + # RBS::Types::ClassSingleton#args was added in RBS 4.0 + @args = raw_decl.respond_to?(:args) ? raw_decl.args.map {|arg| AST.create_rbs_type(arg, lenv) } : [] end attr_reader :cpath, :toplevel