Skip to content

Commit 76e5586

Browse files
committed
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.
1 parent 24cf28e commit 76e5586

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/typeprof/core/ast/sig_type.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def self.typecheck_for_module(genv, changes, f_mod, f_args, a_vtx, subst)
55
a_vtx.each_type do |ty|
66
ty = ty.base_type(genv)
77
while ty
8-
if ty.mod == f_mod
8+
if ty.mod == f_mod && ty.is_a?(Type::Instance)
99
args_all_match = true
1010
f_args.zip(ty.args) do |f_arg_node, a_arg_ty|
1111
unless f_arg_node.typecheck(genv, changes, a_arg_ty, subst)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## update
2+
class C
3+
def self.foo=(v)
4+
v.is_a?(Module)
5+
end
6+
7+
self.foo = 1
8+
end

0 commit comments

Comments
 (0)