* [ruby-core:69704] [Ruby trunk - Bug #11294] [Open] Possible bug in Object.const_get
[not found] <redmine.issue-11294.20150622212345@ruby-lang.org>
@ 2015-06-22 21:23 ` andrew.kozin
2015-06-22 23:21 ` [ruby-core:69707] [Ruby trunk - Bug #11294] [Rejected] " nobu
2015-06-23 12:00 ` [ruby-core:69710] [Ruby trunk - Bug #11294] " andrew.kozin
2 siblings, 0 replies; 3+ messages in thread
From: andrew.kozin @ 2015-06-22 21:23 UTC (permalink / raw)
To: ruby-core
Issue #11294 has been reported by Andrew Kozin.
----------------------------------------
Bug #11294: Possible bug in Object.const_get
https://bugs.ruby-lang.org/issues/11294
* Author: Andrew Kozin
* Status: Open
* Priority: Normal
* Assignee:
* ruby -v: 2.2
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
~~~
module Foo; end
module Foo::Baz; end
module Bar; end
module Bar::Qux; end
Object.const_get "Foo::Baz::Bar::Qux"
# => Bar::Qux
~~~
Why on earth it is found at all?
It seems pretty weird to me.
The real problem arises later, when I add `Foo::Bar::Qux`:
~~~
module Foo::Bar; end
module Foo::Bar::Qux; end
~~~
then the tree becomes as following:
~~~
Foo::Bar::Qux
Foo::Baz
Bar::Qux
~~~
But the result remains the same:
~~~
Object.const_get "Foo::Baz::Bar::Qux"
# => Bar::Qux
~~~
Here I'd expect searching "Foo::Baz::Bar::Qux" to
* either return nothing (this is less astonished, because there is no such constant),
* or find the closest `Bar::Qux` to `Foo::Bar`, that is `Foo::Bar::Qux`, not the `Bar::Qux`
I cannot even understand the logic that follows the `Object.const_get` in providing such a result.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 3+ messages in thread
* [ruby-core:69707] [Ruby trunk - Bug #11294] [Rejected] Possible bug in Object.const_get
[not found] <redmine.issue-11294.20150622212345@ruby-lang.org>
2015-06-22 21:23 ` [ruby-core:69704] [Ruby trunk - Bug #11294] [Open] Possible bug in Object.const_get andrew.kozin
@ 2015-06-22 23:21 ` nobu
2015-06-23 12:00 ` [ruby-core:69710] [Ruby trunk - Bug #11294] " andrew.kozin
2 siblings, 0 replies; 3+ messages in thread
From: nobu @ 2015-06-22 23:21 UTC (permalink / raw)
To: ruby-core
Issue #11294 has been updated by Nobuyoshi Nakada.
Description updated
Status changed from Open to Rejected
Toplevel constants are defined under `Object` context, which are inherited by every contexts.
Your results are same as:
~~~ruby
module Foo::Baz; p Bar::Qux; end #=> Bar::Qux
~~~
> * or find the closest `Bar::Qux` to `Foo::Bar`, that is `Foo::Bar::Qux`, not the `Bar::Qux`
It's *not* close.
And `Foo::Baz::Bar` is different from `Foo::Bar`.
----------------------------------------
Bug #11294: Possible bug in Object.const_get
https://bugs.ruby-lang.org/issues/11294#change-53084
* Author: Andrew Kozin
* Status: Rejected
* Priority: Normal
* Assignee:
* ruby -v: 2.2
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
~~~ruby
module Foo; end
module Foo::Baz; end
module Bar; end
module Bar::Qux; end
Object.const_get "Foo::Baz::Bar::Qux"
# => Bar::Qux
~~~
Why on earth it is found at all?
It seems pretty weird to me.
The real problem arises later, when I add `Foo::Bar::Qux`:
~~~ruby
module Foo::Bar; end
module Foo::Bar::Qux; end
~~~
then the tree becomes as following:
~~~ruby
Foo::Bar::Qux
Foo::Baz
Bar::Qux
~~~
But the result remains the same:
~~~ruby
Object.const_get "Foo::Baz::Bar::Qux"
# => Bar::Qux
~~~
Here I'd expect searching `"Foo::Baz::Bar::Qux"` to
* either return nothing (this is less astonished, because there is no such constant),
* or find the closest `Bar::Qux` to `Foo::Bar`, that is `Foo::Bar::Qux`, not the `Bar::Qux`
I cannot even understand the logic that follows the `Object.const_get` in providing such a result.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 3+ messages in thread
* [ruby-core:69710] [Ruby trunk - Bug #11294] Possible bug in Object.const_get
[not found] <redmine.issue-11294.20150622212345@ruby-lang.org>
2015-06-22 21:23 ` [ruby-core:69704] [Ruby trunk - Bug #11294] [Open] Possible bug in Object.const_get andrew.kozin
2015-06-22 23:21 ` [ruby-core:69707] [Ruby trunk - Bug #11294] [Rejected] " nobu
@ 2015-06-23 12:00 ` andrew.kozin
2 siblings, 0 replies; 3+ messages in thread
From: andrew.kozin @ 2015-06-23 12:00 UTC (permalink / raw)
To: ruby-core
Issue #11294 has been updated by Andrew Kozin.
Thank you, Nobuyoshi, for your answering.
Now I see the reason, but IMHO this behaviour is a bit perplexing.
I think it still be useful to have a "strict" version of `Object.get_const` that would treat the namespace literally with a syntax of sorts:
~~~
Object.get_const "Foo::Baz::Bar::Qux", strict: true
# => NameError: uninitialized constant Foo::Baz::Bar
~~~
----------------------------------------
Bug #11294: Possible bug in Object.const_get
https://bugs.ruby-lang.org/issues/11294#change-53088
* Author: Andrew Kozin
* Status: Rejected
* Priority: Normal
* Assignee:
* ruby -v: 2.2
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
~~~ruby
module Foo; end
module Foo::Baz; end
module Bar; end
module Bar::Qux; end
Object.const_get "Foo::Baz::Bar::Qux"
# => Bar::Qux
~~~
Why on earth it is found at all?
It seems pretty weird to me.
The real problem arises later, when I add `Foo::Bar::Qux`:
~~~ruby
module Foo::Bar; end
module Foo::Bar::Qux; end
~~~
then the tree becomes as following:
~~~ruby
Foo::Bar::Qux
Foo::Baz
Bar::Qux
~~~
But the result remains the same:
~~~ruby
Object.const_get "Foo::Baz::Bar::Qux"
# => Bar::Qux
~~~
Here I'd expect searching `"Foo::Baz::Bar::Qux"` to
* either return nothing (this is less astonished, because there is no such constant),
* or find the closest `Bar::Qux` to `Foo::Bar`, that is `Foo::Bar::Qux`, not the `Bar::Qux`
I cannot even understand the logic that follows the `Object.const_get` in providing such a result.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-06-23 11:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <redmine.issue-11294.20150622212345@ruby-lang.org>
2015-06-22 21:23 ` [ruby-core:69704] [Ruby trunk - Bug #11294] [Open] Possible bug in Object.const_get andrew.kozin
2015-06-22 23:21 ` [ruby-core:69707] [Ruby trunk - Bug #11294] [Rejected] " nobu
2015-06-23 12:00 ` [ruby-core:69710] [Ruby trunk - Bug #11294] " andrew.kozin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).