Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not cached as it may be replaced #1656

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions lib/rbs/test/type_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ 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 @@ -21,7 +19,6 @@ 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 @@ -208,11 +205,9 @@ def each_sample(array, &block)
end

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

def is_double?(value)
Expand Down
49 changes: 49 additions & 0 deletions test/rbs/test/tester_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,53 @@ 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