From: "fxn (Xavier Noria) via ruby-core" Date: 2025-05-10T09:50:31+00:00 Subject: [ruby-core:121975] [Ruby Bug#21322] Namespaces and builtin classes as arguments and return values Issue #21322 has been updated by fxn (Xavier Noria). For example, if I instead fo ```ruby ns = Namespace.new ns.require_relative 'foo' c = Class.new c::X = 1 ns::C.x(c) ``` then `obj::X` resolves as expected in the method. Method calls somehow seems to be swapping `VALUE`s that correspond to builtin classes on the fly. Please excuse I am not reading the source code to answer this myself, I do not know enough about CRuby internals to understand the patch and its implications. ---------------------------------------- Bug #21322: Namespaces and builtin classes as arguments and return values https://bugs.ruby-lang.org/issues/21322#change-113090 * Author: fxn (Xavier Noria) * Status: Open * Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- @tagomoris thanks for the docs under `doc/namespace.md`. Unless I missed it, I believe there is an edge case related to builtin classes (using the vocabulary there). Consider: ```ruby # test.rb ns = Namespace.new ns.require_relative 'foo' X = 1 ns::C.x(Object) # foo.rb class C def self.x(obj) obj::X end end ``` `obj::X` raises. I believe this is consistent with the feature, but maybe would deserve docs, because from the point of view of the Ruby programmer I am passing an object, no constant name resolution is happening in `foo.rb`. See what I mean? I believe, from my tests, that something analogous happens if `ns::C.x` returns (the namespaced) `Object`. In the main namespace, you don't get the object passed up as-is. I am also curious about how is this implemented (maybe to comment here, not necessarily in the docs). -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/