* [ruby-core:95786] [Ruby master Bug#16340] There are cases where `eval("_ 1")` does not refer to Numbered parameter
[not found] <redmine.issue-16340.20191111124505@ruby-lang.org>
@ 2019-11-11 12:45 ` manga.osyo
2019-11-11 13:40 ` [ruby-core:95787] " eregontp
2019-11-13 15:31 ` [ruby-core:95844] " manga.osyo
2 siblings, 0 replies; 3+ messages in thread
From: manga.osyo @ 2019-11-11 12:45 UTC (permalink / raw)
To: ruby-core
Issue #16340 has been reported by osyo (manga osyo).
----------------------------------------
Bug #16340: There are cases where `eval("_ 1")` does not refer to Numbered parameter
https://bugs.ruby-lang.org/issues/16340
* Author: osyo (manga osyo)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
* ruby -v: ruby 2.7.0dev (2019-11-11T10:03:43Z trunk 9d3213ac85) [x86_64-linux]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
## Steps to reproduce
1. Define local variable `_1` outside block
2. Call Numbered parameter in block
3. Call `eval("_1")` in same block
## Expected behavior
```ruby
_1 = :local_variable
proc {
_1
# return Numbered parameter(_1)
eval("_1") # => :argument
}.call :argument
```
## Actual behavior
```ruby
_1 = :local_variable
proc {
_1
# return local variables outside block
eval("_1") # => :local_variable
}.call :argument
```
This is strange behavior because I want to expect to reference `_1` in block.
## Note
* Return Numbered parameter if not define local variables outside block
```ruby
# _1 = :local_variable
proc {
_1
# Actual behavior
# return Numbered parameter
eval("_1") # => :argument
}.call :argument
```
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 3+ messages in thread
* [ruby-core:95787] [Ruby master Bug#16340] There are cases where `eval("_ 1")` does not refer to Numbered parameter
[not found] <redmine.issue-16340.20191111124505@ruby-lang.org>
2019-11-11 12:45 ` [ruby-core:95786] [Ruby master Bug#16340] There are cases where `eval("_ 1")` does not refer to Numbered parameter manga.osyo
@ 2019-11-11 13:40 ` eregontp
2019-11-13 15:31 ` [ruby-core:95844] " manga.osyo
2 siblings, 0 replies; 3+ messages in thread
From: eregontp @ 2019-11-11 13:40 UTC (permalink / raw)
To: ruby-core
Issue #16340 has been updated by Eregon (Benoit Daloze).
Status changed from Open to Rejected
I think the behavior is expected.
`_1` is a local variable in your example and eval can access local variables outside of it.
However, I don't think `_1` can work as numbered parameter inside an eval for a block outside the eval, because then we'd change the block arity dynamically.
What would be the Proc#arity of `lambda { _1 + eval("_#{rand(5)}") }.arity` ?
IMHO, `_1` shouldn't be supported inside `eval` as a numbered parameter when it refers to something outside `eval`.
So I think the current behavior is fine, and needs to be kept for compatibility if `_<n>` is used as a local variable.
Do you have any realistic use case where you would want your expected behavior?
I mark this as rejected because I believe it's unsolvable.
----------------------------------------
Bug #16340: There are cases where `eval("_ 1")` does not refer to Numbered parameter
https://bugs.ruby-lang.org/issues/16340#change-82608
* Author: osyo (manga osyo)
* Status: Rejected
* Priority: Normal
* Assignee:
* Target version:
* ruby -v: ruby 2.7.0dev (2019-11-11T10:03:43Z trunk 9d3213ac85) [x86_64-linux]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
## Steps to reproduce
1. Define local variable `_1` outside block
2. Call Numbered parameter in block
3. Call `eval("_1")` in same block
## Expected behavior
```ruby
_1 = :local_variable
proc {
_1
# return Numbered parameter(_1)
eval("_1") # => :argument
}.call :argument
```
## Actual behavior
```ruby
_1 = :local_variable
proc {
_1
# return local variables outside block
eval("_1") # => :local_variable
}.call :argument
```
This is strange behavior because I want to expect to reference `_1` in block.
## Note
* Return Numbered parameter if not define local variables outside block
```ruby
# _1 = :local_variable
proc {
_1
# Actual behavior
# return Numbered parameter
eval("_1") # => :argument
}.call :argument
```
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 3+ messages in thread
* [ruby-core:95844] [Ruby master Bug#16340] There are cases where `eval("_ 1")` does not refer to Numbered parameter
[not found] <redmine.issue-16340.20191111124505@ruby-lang.org>
2019-11-11 12:45 ` [ruby-core:95786] [Ruby master Bug#16340] There are cases where `eval("_ 1")` does not refer to Numbered parameter manga.osyo
2019-11-11 13:40 ` [ruby-core:95787] " eregontp
@ 2019-11-13 15:31 ` manga.osyo
2 siblings, 0 replies; 3+ messages in thread
From: manga.osyo @ 2019-11-13 15:31 UTC (permalink / raw)
To: ruby-core
Issue #16340 has been updated by osyo (manga osyo).
@Eregon
Thanks comment!
> Do you have any realistic use case where you would want your expected behavior?
No.
However, I thought it was strange behavior and reported.
I agree to reject.
----------------------------------------
Bug #16340: There are cases where `eval("_ 1")` does not refer to Numbered parameter
https://bugs.ruby-lang.org/issues/16340#change-82677
* Author: osyo (manga osyo)
* Status: Rejected
* Priority: Normal
* Assignee:
* Target version:
* ruby -v: ruby 2.7.0dev (2019-11-11T10:03:43Z trunk 9d3213ac85) [x86_64-linux]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
## Steps to reproduce
1. Define local variable `_1` outside block
2. Call Numbered parameter in block
3. Call `eval("_1")` in same block
## Expected behavior
```ruby
_1 = :local_variable
proc {
_1
# return Numbered parameter(_1)
eval("_1") # => :argument
}.call :argument
```
## Actual behavior
```ruby
_1 = :local_variable
proc {
_1
# return local variables outside block
eval("_1") # => :local_variable
}.call :argument
```
This is strange behavior because I want to expect to reference `_1` in block.
## Note
* Return Numbered parameter if not define local variables outside block
```ruby
# _1 = :local_variable
proc {
_1
# Actual behavior
# return Numbered parameter
eval("_1") # => :argument
}.call :argument
```
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-11-13 15:32 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-16340.20191111124505@ruby-lang.org>
2019-11-11 12:45 ` [ruby-core:95786] [Ruby master Bug#16340] There are cases where `eval("_ 1")` does not refer to Numbered parameter manga.osyo
2019-11-11 13:40 ` [ruby-core:95787] " eregontp
2019-11-13 15:31 ` [ruby-core:95844] " manga.osyo
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).