[ruby-core:116969] [Ruby master Bug#20308] `it` and numbered parameters do not work in `eval`

Issue #20308 has been reported by kddnewton (Kevin Newton). ---------------------------------------- Bug #20308: `it` and numbered parameters do not work in `eval` https://bugs.ruby-lang.org/issues/20308 * Author: kddnewton (Kevin Newton) * Status: Open * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- I am not sure if this is a purposeful restriction or not, so I apologize if this is not a "bug" per se. Currently if you use `it` or `_1` (numbered parameters) in `eval` they do not work with `compile.c`: ``` irb(main):001> 1.tap { eval("_1") } (eval):1:in `block in <top (required)>': undefined local variable or method `_1' for main:Object (NameError) Did you mean? _ ``` They work accidentally with prism because I didn't know this wasn't allowed. Is it a bug? Or is this on purpose? -- https://bugs.ruby-lang.org/

Issue #20308 has been updated by matheusrich (Matheus Richard). Interesting behavior. I'd expect that to work since other "kinds of arguments" work: ```rb def foo(*) eval "puts(*)" end def foo(**) eval "puts(**)" end def foo(...) eval "puts(...)" end ``` ---------------------------------------- Bug #20308: `it` and numbered parameters do not work in `eval` https://bugs.ruby-lang.org/issues/20308#change-107019 * Author: kddnewton (Kevin Newton) * Status: Open * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- I am not sure if this is a purposeful restriction or not, so I apologize if this is not a "bug" per se. Currently if you use `it` or `_1` (numbered parameters) in `eval` they do not work with `compile.c`: ``` irb(main):001> 1.tap { eval("_1") } (eval):1:in `block in <top (required)>': undefined local variable or method `_1' for main:Object (NameError) Did you mean? _ ``` They work accidentally with prism because I didn't know this wasn't allowed. Is it a bug? Or is this on purpose? -- https://bugs.ruby-lang.org/

Issue #20308 has been updated by jeremyevans0 (Jeremy Evans). My understanding is the parse.y behavior is expected, because use of `_1`/`it` inside the block changes the block's arity: ```ruby lambda{it}.arity # => 1 lambda{eval('it')}.arity # => 0 ``` So if we supported `eval('it')` in non-lambda procs, it would make support inconsistent with lambda procs. ---------------------------------------- Bug #20308: `it` and numbered parameters do not work in `eval` https://bugs.ruby-lang.org/issues/20308#change-107021 * Author: kddnewton (Kevin Newton) * Status: Open * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- I am not sure if this is a purposeful restriction or not, so I apologize if this is not a "bug" per se. Currently if you use `it` or `_1` (numbered parameters) in `eval` they do not work with `compile.c`: ``` irb(main):001> 1.tap { eval("_1") } (eval):1:in `block in <top (required)>': undefined local variable or method `_1' for main:Object (NameError) Did you mean? _ ``` They work accidentally with prism because I didn't know this wasn't allowed. Is it a bug? Or is this on purpose? -- https://bugs.ruby-lang.org/

Issue #20308 has been updated by alanwu (Alan Wu). Looks like it's a known limitation and discussed before #18837. ---------------------------------------- Bug #20308: `it` and numbered parameters do not work in `eval` https://bugs.ruby-lang.org/issues/20308#change-107023 * Author: kddnewton (Kevin Newton) * Status: Open * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- I am not sure if this is a purposeful restriction or not, so I apologize if this is not a "bug" per se. Currently if you use `it` or `_1` (numbered parameters) in `eval` they do not work with `compile.c`: ``` irb(main):001> 1.tap { eval("_1") } (eval):1:in `block in <top (required)>': undefined local variable or method `_1' for main:Object (NameError) Did you mean? _ ``` They work accidentally with prism because I didn't know this wasn't allowed. Is it a bug? Or is this on purpose? -- https://bugs.ruby-lang.org/

Issue #20308 has been updated by kddnewton (Kevin Newton). Ahh! Thank you @jeremyevans0 and @alanwu I knew there must have been a reason. I'll close this. ---------------------------------------- Bug #20308: `it` and numbered parameters do not work in `eval` https://bugs.ruby-lang.org/issues/20308#change-107024 * Author: kddnewton (Kevin Newton) * Status: Open * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- I am not sure if this is a purposeful restriction or not, so I apologize if this is not a "bug" per se. Currently if you use `it` or `_1` (numbered parameters) in `eval` they do not work with `compile.c`: ``` irb(main):001> 1.tap { eval("_1") } (eval):1:in `block in <top (required)>': undefined local variable or method `_1' for main:Object (NameError) Did you mean? _ ``` They work accidentally with prism because I didn't know this wasn't allowed. Is it a bug? Or is this on purpose? -- https://bugs.ruby-lang.org/
participants (4)
-
alanwu (Alan Wu)
-
jeremyevans0 (Jeremy Evans)
-
kddnewton (Kevin Newton)
-
matheusrich (Matheus Richard)