From: ibylich@... Date: 2019-10-10T00:42:46+00:00 Subject: [ruby-core:95294] [Ruby master Bug#16248] Unclear semantics of the "numbered parameter is already used" error Issue #16248 has been reported by ibylich (Ilya Bylich). ---------------------------------------- Bug #16248: Unclear semantics of the "numbered parameter is already used" error https://bugs.ruby-lang.org/issues/16248 * Author: ibylich (Ilya Bylich) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.7.0dev (2019-10-02T14:56:28Z trunk ef697388be) [x86_64-darwin18] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN ---------------------------------------- Numbered parameters now have an underscore as a prefix: ``` ruby ->{ _1 }.call(1) => 1 ``` And it's not allowed to use them in a block if an outer block also uses them: ``` ruby ->{ _1; ->{_2} } SyntaxError ((irb):4: numbered parameter is already used in) (irb):4: outer block here ->{ _1; ->{_2} } ^~ ``` even if the usage goes after declaring an inner block with numbered params: ``` ruby ->{ ->{_2}; _1 } SyntaxError ((irb):5: numbered parameter is already used in) (irb):5: inner block here ->{ ->{_2}; _1 } ^~ ``` So far it's clear. Then comes the second part: if you wrap an inner block into a method you get a valid syntax: ``` ruby ->{ def m; ->{_2}; end; _1 } => # ``` but if you swap block statements you get an error: ``` ruby >{ _1; def m; ->{_2}; end } SyntaxError ((irb):6: numbered parameter is already used in) (irb):6: outer block here ->{ _1; def m; ->{_2}; end } ^~ ``` It looks like a consistency issue to me. Is there a strict rule that defines what is valid what is not? -- https://bugs.ruby-lang.org/ Unsubscribe: