From aab5facb0afdfc635b5e6e2c6507d5d5cba0746c Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Fri, 23 Aug 2024 11:01:42 +0900 Subject: [PATCH] Temporarily ignore "return" in non-method scope Currently TypeProf does not support `define_method`. A return statement in `define_method` is considered as a non-method-scope return, which is not well supported. This change temporarily ignores such a case. --- lib/typeprof/core/ast/control.rb | 4 ++-- scenario/misc/define_method_return.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 scenario/misc/define_method_return.rb diff --git a/lib/typeprof/core/ast/control.rb b/lib/typeprof/core/ast/control.rb index a301a959..676f8ffc 100644 --- a/lib/typeprof/core/ast/control.rb +++ b/lib/typeprof/core/ast/control.rb @@ -313,8 +313,8 @@ def subnodes = { arg: } def install0(genv) @arg.install(genv) - e_ret = @lenv.get_var(:"*expected_method_ret") - @lenv.add_return_box(@changes.add_escape_box(genv, @arg.ret, e_ret)) + e_ret = @lenv.locals[:"*expected_method_ret"] + @lenv.add_return_box(@changes.add_escape_box(genv, @arg.ret, e_ret)) if e_ret Source.new(Type::Bot.new(genv)) end end diff --git a/scenario/misc/define_method_return.rb b/scenario/misc/define_method_return.rb new file mode 100644 index 00000000..8ddf9866 --- /dev/null +++ b/scenario/misc/define_method_return.rb @@ -0,0 +1,8 @@ +## update +class Foo + define_method(:foo) { return } +end + +## assert +class Foo +end