From 85e495e8bbbe19aaa09a731de20a3f607e8752b9 Mon Sep 17 00:00:00 2001 From: Soutaro Matsumoto Date: Tue, 24 Nov 2020 00:24:01 +0900 Subject: [PATCH] Make AMC method name random --- lib/rbs/test/hook.rb | 30 +++++++++++++++++------------- test/rbs/test/runtime_test_test.rb | 29 +++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 13 deletions(-) diff --git a/lib/rbs/test/hook.rb b/lib/rbs/test/hook.rb index 6cbb17a1e..49bb1dc76 100644 --- a/lib/rbs/test/hook.rb +++ b/lib/rbs/test/hook.rb @@ -27,26 +27,28 @@ module Hook :>> => "rshift", :~ => "tilda" } - def self.alias_names(target) + def self.alias_names(target, random) + suffix = "#{RBS::Test.suffix}_#{random}" + case target when *OPERATORS.keys name = OPERATORS[target] [ - "#{name}____with__#{Test.suffix}", - "#{name}____without__#{Test.suffix}" + "#{name}____with__#{suffix}", + "#{name}____without__#{suffix}" ] else aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1 [ - "#{aliased_target}__with__#{Test.suffix}#{punctuation}", - "#{aliased_target}__without__#{Test.suffix}#{punctuation}" + "#{aliased_target}__with__#{suffix}#{punctuation}", + "#{aliased_target}__without__#{suffix}#{punctuation}" ] end end - def self.setup_alias_method_chain(klass, target) - with_method, without_method = alias_names(target) + def self.setup_alias_method_chain(klass, target, random:) + with_method, without_method = alias_names(target, random) RBS.logger.debug "alias name: #{target}, #{with_method}, #{without_method}" @@ -65,8 +67,8 @@ def self.setup_alias_method_chain(klass, target) end end - def self.hook_method_source(prefix, method_name, key) - with_name, without_name = alias_names(method_name) + def self.hook_method_source(prefix, method_name, key, random:) + with_name, without_name = alias_names(method_name, random) full_method_name = "#{prefix}#{method_name}" [__LINE__ + 1, < 'Foo,Bar' }, rbs_content: < void +end + +class Bar + def foo: (Integer) -> void +end +RBS +class Foo + def foo(x) + ::RBS.logger.error("Foo#foo") + puts "Foo#foo: x=#{x}" + end +end + +class Bar < Foo + def foo(x) + ::RBS.logger.error("Bar#foo") + puts "Bar#foo: x=#{x}" + super + end +end + +Bar.new.foo(30) +RUBY end end