From: nobu@... Date: 2019-05-06T15:47:07+00:00 Subject: [ruby-core:92575] [Ruby trunk Bug#15789] Parse error when numbered parameter is used in a lambda that is a default value of other optarg Issue #15789 has been updated by nobu (Nobuyoshi Nakada). jeremyevans0 (Jeremy Evans) wrote: > I think the `ordinary parameter is defined` error makes sense if you consider the block starting at the `->` and not the `{`. Especially when you consider the older lambda/proc syntax uses the same error: > > ```ruby > lambda { |a=@1| a } > # SyntaxError ((irb):1: ordinary parameter is defined) > ``` I've thought inside braces and outside braces are different. That is, in this code, the `@1` should mean the parameter of the outer `proc`. ```ruby proc {->(a = @1) {a}}.call(42) ``` But now I changed the mind. The scope inside parentheses should be separated from the outside. ---------------------------------------- Bug #15789: Parse error when numbered parameter is used in a lambda that is a default value of other optarg https://bugs.ruby-lang.org/issues/15789#change-77934 * Author: ibylich (Ilya Bylich) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.7.0dev (2019-04-24 trunk cf930985da) [x86_64-darwin18] * Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN ---------------------------------------- Sorry if the name of the ticket is not desccriptive While working on backporting these commits into a parser gem: https://github.com/ruby/ruby/commit/6ca9e7cc0785c33f6d382176dbd79d6c91db72fe https://github.com/ruby/ruby/commit/ae07b66aaa092c59ac9d544c9b582712290dc357 ... I've found a weird case that throws a SyntaxError: ``` ruby > def m(a = ->{@1}); end SyntaxError ((irb):10: ordinary parameter is defined) def m(a = ->{@1}); end ^~ ``` And same errors gets thrown when I pass a lambda with numparams to lambda optarg: ``` ruby > ->(optarg = ->{@1}) {} SyntaxError ((irb):1: ordinary parameter is defined) ->(optarg = ->{@1}) {} ^~ ``` I guess the reason for that is that p->max_numparam should be organized as a stack, not a plain shared value. ---Files-------------------------------- fix-numbered-parameter-in-optarg-default-value.patch (546 Bytes) fix-numbered-parameter-in-optarg-default-value-v2.patch (1.42 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: