Skip to content

Commit

Permalink
Revert "Merge pull request #1656 from ksss/fix-tester"
Browse files Browse the repository at this point in the history
This reverts commit c1f4c8f, reversing
changes made to 98f2ed1.
  • Loading branch information
soutaro committed Dec 20, 2023
1 parent 0647eb1 commit b23f152
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 52 deletions.
11 changes: 8 additions & 3 deletions lib/rbs/test/type_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class TypeCheck
attr_reader :instance_class
attr_reader :class_class

attr_reader :const_cache

DEFAULT_SAMPLE_SIZE = 100

def initialize(self_class:, builder:, sample_size:, unchecked_classes:, instance_class: Object, class_class: Module)
Expand All @@ -19,6 +21,7 @@ def initialize(self_class:, builder:, sample_size:, unchecked_classes:, instance
@builder = builder
@sample_size = sample_size
@unchecked_classes = unchecked_classes.uniq
@const_cache = {}
end

def overloaded_call(method, method_name, call, errors:)
Expand Down Expand Up @@ -205,9 +208,11 @@ def each_sample(array, &block)
end

def get_class(type_name)
Object.const_get(type_name.to_s)
rescue NameError
nil
const_cache[type_name] ||= begin
Object.const_get(type_name.to_s)
rescue NameError
nil
end
end

def is_double?(value)
Expand Down
49 changes: 0 additions & 49 deletions test/rbs/test/tester_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,53 +52,4 @@ def move: (?x: Integer, ?y: Integer) -> void
end
end
end

class Foo
end

# See also https://github.com/ruby/rbs/issues/1636
def test_redefine_class
SignatureManager.new(system_builtin: true) do |manager|
manager.files[Pathname("foo.rbs")] = <<EOF
module RBS
module Test
module TesterTest
class Foo
def foo: (Foo) -> void
end
end
end
end
EOF
manager.build do |env, path|
builder = RBS::DefinitionBuilder.new(env: env)
definition = builder.build_instance(type_name("::RBS::Test::TesterTest::Foo"))

checker = RBS::Test::Tester::MethodCallTester.new(Object, builder, definition, kind: :instance, sample_size: 100, unchecked_classes: [])

checker.call(
Object.new,
CallTrace.new(
method_name: :foo,
method_call: ArgumentsReturn.return(arguments: [Foo.new], value: nil),
block_calls: [],
block_given: false
)
)

self.class.send(:remove_const, :Foo)
self.class.const_set(:Foo, Class.new)

checker.call(
Object.new,
CallTrace.new(
method_name: :foo,
method_call: ArgumentsReturn.return(arguments: [Foo.new], value: nil),
block_calls: [],
block_given: false
)
)
end
end
end
end

0 comments on commit b23f152

Please sign in to comment.