Comments (7)
@HoneyryderChuck
Thank you for the explanation. I understand the issue now.
When remove_const/const_set
is executed and the class object is swapped, the old class remains in RBS::Test::TypeCheck#const_cache
. Consequently, when calling #is_a?
for the Types::ClassInstance
check, the test fails because the object_id
differs.
If we can hook into remove_const
to clear RBS::Test::TypeCheck#const_cache
, it seems we can solve the problem. This RBS::Test::TypeCheck#const_cache
exists as a memoized cache within the RBS::Test::Tester::MethodCallTester
instance, so we need to find this instance. However, currently, there doesn't seem to be a way to retrieve it.
For a makeshift solution, you could do something like the following, which should work for now:
diff --git a/lib/rbs/test/observer.rb b/lib/rbs/test/observer.rb
index ff023871..05cc0394 100644
--- a/lib/rbs/test/observer.rb
+++ b/lib/rbs/test/observer.rb
@@ -13,6 +13,10 @@ module RBS
def register(key, object = nil, &block)
@@observers[key] = object || block
end
+
+ def observers
+ @@observers
+ end
end
end
end
diff --git a/lib/rbs/test/setup.rb b/lib/rbs/test/setup.rb
index 1a8041c9..16c30e47 100644
--- a/lib/rbs/test/setup.rb
+++ b/lib/rbs/test/setup.rb
@@ -75,6 +75,21 @@ TracePoint.trace :end do |tp|
end
end
+hook = Module.new{
+ def remove_const(name)
+ super
+ end
+}
+Module.prepend(hook)
+
+TracePoint.new(:call) do |tp|
+ name = tp.binding.local_variable_get(:name)
+ type_name = TypeName("::#{tp.self}::#{name}")
+ RBS::Test::Observer.observers.values.each do |method_call_tester|
+ method_call_tester.check.const_cache.delete(type_name)
+ end
+end.enable(target: hook.instance_method(:remove_const))
+
at_exit do
if $!.nil? || $!.is_a?(SystemExit) && $!.success?
if tester.targets.empty?
Alternatively, a very simple fix would be to just stop caching.
diff --git a/lib/rbs/test/type_check.rb b/lib/rbs/test/type_check.rb
index ac0edbc3..6ed8d134 100644
--- a/lib/rbs/test/type_check.rb
+++ b/lib/rbs/test/type_check.rb
@@ -208,11 +208,9 @@ module RBS
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)
@soutaro How about this?
from rbs.
@HoneyryderChuck Thank you for reporting the problem.
Hmm, rbs/test/setup
is loaded before other libraries, net/http
is defined, and webmock
assigns new class to Net::HTTP
...
It seems like we need to add a hook to setup runtime type checkers after loading webmock
.
I also wonder if @ksss has any idea about this?
from rbs.
It is possible to hook remove_const
and const_set
with TracePoint, but I'm not yet clear on the potential issues.
Do you have a way to reproduce the problem?
from rbs.
I couldn't find narrow down the smallest possible reproduction, unfortunately. The error can be reproduced with httpx integration, test suite, as httpx
performs the same "remove_const/const_set" trick in its webmock integrations. Just: clone the repo, bundle install
, set up the rbs env vars and run bundle exec rake integration_tests
.
from rbs.
Disable the caching! Seems like there were no strong reason to introduce it... #356
from rbs.
I'll send PR soon.
from rbs.
Thx everyone
from rbs.
Related Issues (20)
- rbs/test: stack level too deep when calling super from prepend HOT 1
- "singleton(class with this mixin)" is not supported
- [RBS::Test] Cannot call `super` in block
- How to deal with gems with integrations
- Incorrrect signatures for ruby 3.3.0
- Type signature failures in net-http
- support * in tuples HOT 3
- Position of RBS::Location should be byte length HOT 3
- `rbs collection install` fails with parse error HOT 8
- Identify and skip `development` dependencies
- Support type narrowing HOT 2
- Cannot call `super` in block
- Test for project integration HOT 1
- Test for project integration
- %a{pure} does not seem to work for attr_reader HOT 3
- inline type narrowing HOT 1
- Array(T | Array[T]) not well handled HOT 2
- Method overload narrowing
- Windows build is failing HOT 9
- calling #each on obj typed with record yields |bot, bot| types HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rbs.