Project

General

Profile

Actions

Bug #17431

closed

paren_nest is not reset in parse.y after "foo.[]= value"

Added by ibylich (Ilya Bylich) almost 4 years ago. Updated almost 4 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 3.0.0dev (2020-12-23T14:40:04Z master 94015200b6) [x86_64-darwin19]
[ruby-core:101651]

Description

p->lex.paren_nest is equal to 1 after the following code:

self.[]= foo

paren_nest is used to differentiate ... for ranges/forwarded arguments, and so ./miniruby -we 'foo.[]= bar, ...' gives no ... at EOL, should be parenthesized? warning (./miniruby -we 'foo.x= bar, ...' does).

Also it's used to differentiate kDO vs kDO_LAMBDA, so I believe there are code samples with lambdas and .[]= calls that can't be handled by Ruby but are technically valid.

Updated by mame (Yusuke Endoh) almost 4 years ago

  • Status changed from Open to Assigned
  • Assignee set to nobu (Nobuyoshi Nakada)

Updated by ibylich (Ilya Bylich) almost 4 years ago

Ok, got an example with lambdas:

$ ./miniruby -ce '->(opt = (foo.[]= bar)) do end'
-e:1: syntax error, unexpected `do', expecting `do' for lambda or tLAMBEG
->(opt = (foo.[]= bar)) do end
-e:1: warning: paren_nest = 1

$ ./miniruby -ce '->(opt = (foo.x= bar)) do end'
-e:1: warning: paren_nest = 0

Syntax OK

Updated by ibylich (Ilya Bylich) almost 4 years ago

The following patch seems to be the fix:

diff --git a/parse.y b/parse.y
index c65a469a..a4f6bcc8 100644
--- a/parse.y
+++ b/parse.y
@@ -9668,6 +9669,7 @@ parser_yylex(struct parser_params *p)
        p->lex.paren_nest++;
        if (IS_AFTER_OPERATOR()) {
            if ((c = nextc(p)) == ']') {
+                p->lex.paren_nest--;
                SET_LEX_STATE(EXPR_ARG);
                if ((c = nextc(p)) == '=') {
                    return tASET;
Actions #4

Updated by nobu (Nobuyoshi Nakada) almost 4 years ago

  • Status changed from Assigned to Closed

Applied in changeset git|4a8ff22f0c9f8a7cd9a68f49523fa2573a4326e9.


Reset paren_nest at tAREF and tASET [Bug #17431]

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0