From 595059ff7e159acb243f9a92d9b46260ab3bc878 Mon Sep 17 00:00:00 2001 From: Takumi Shotoku Date: Mon, 15 Sep 2025 20:19:37 +0900 Subject: [PATCH] Fix NoMethodError in `TypeProf::Core::Type::Singleton` I encountered the following error: ``` /Users/sinsoku/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/sig_type.rb:10:in `block in typecheck_for_module': undefined method `args' for an instance of TypeProf::Core::Type::Singleton (NoMethodError) f_args.zip(ty.args) do |f_arg_node, a_arg_ty| ^^^^^ from /Users/sinsoku/ghq/github.com/ruby/typeprof/lib/typeprof/core/graph/vertex.rb:11:in `each_key' from /Users/sinsoku/ghq/github.com/ruby/typeprof/lib/typeprof/core/graph/vertex.rb:11:in `each_type' from /Users/sinsoku/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/sig_type.rb:5:in `typecheck_for_module' from /Users/sinsoku/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/sig_type.rb:669:in `typecheck' from /Users/sinsoku/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/sig_type.rb:483:in `block in typecheck' from /Users/sinsoku/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/sig_type.rb:482:in `each' from /Users/sinsoku/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/sig_type.rb:482:in `typecheck' ``` The `args` method is only defined on `Type::Instance`, so it adds a conditional expression to avoid the error. --- lib/typeprof/core/ast/sig_type.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/typeprof/core/ast/sig_type.rb b/lib/typeprof/core/ast/sig_type.rb index 7f5ca9dc..9565e90d 100644 --- a/lib/typeprof/core/ast/sig_type.rb +++ b/lib/typeprof/core/ast/sig_type.rb @@ -5,7 +5,7 @@ def self.typecheck_for_module(genv, changes, f_mod, f_args, a_vtx, subst) a_vtx.each_type do |ty| ty = ty.base_type(genv) while ty - if ty.mod == f_mod + if ty.mod == f_mod && ty.is_a?(Type::Instance) args_all_match = true f_args.zip(ty.args) do |f_arg_node, a_arg_ty| unless f_arg_node.typecheck(genv, changes, a_arg_ty, subst)