From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=3.0 tests=AWL,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY shortcircuit=no autolearn=no autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id A6B651F5AE for ; Sun, 5 Jul 2020 13:30:32 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 70C6E120A65; Sun, 5 Jul 2020 22:30:02 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id E70FD120A62 for ; Sun, 5 Jul 2020 22:29:59 +0900 (JST) Received: by filterdrecv-p3iad2-5b55dcd864-htmgx with SMTP id filterdrecv-p3iad2-5b55dcd864-htmgx-19-5F01D5F1-D 2020-07-05 13:30:25.099213631 +0000 UTC m=+764469.073647013 Received: from herokuapp.com (unknown) by ismtpd0051p1iad1.sendgrid.net (SG) with ESMTP id Si480f-yRsK2bX9wnRLzWg for ; Sun, 05 Jul 2020 13:30:24.942 +0000 (UTC) Date: Sun, 05 Jul 2020 13:30:25 +0000 (UTC) From: manga.osyo@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 74859 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 17013 X-Redmine-Issue-Author: osyo X-Redmine-Sender: osyo X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?EoIqruA4Er0CjiyK1+U6TJuuQMCAZ3OX2ybarlx6ke5ntfRICCGFhv33DGBDjY?= =?us-ascii?Q?9nDceILMhSEbGC+SgGgbdmxTqlov=2F=2FFILWVaQV4?= =?us-ascii?Q?skezprTu0agcLOQK4CduO0tiz182Ye7oQlq9+cX?= =?us-ascii?Q?lDOqLL2ih6tHO+0kXBIp5cOQH+pACYtt36EmAVo?= =?us-ascii?Q?+oZ5JtytF9VRYJQ4OSNhbKLrs04fxxjDLi1vnx6?= =?us-ascii?Q?R=2FOovJ1pv4KvyKw8g=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 99069 Subject: [ruby-core:99069] [Ruby master Bug#17013] `RubyVM::AbstractSyntaxTree.parse("struct.field += foo")` has no operator X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #17013 has been reported by osyo (manga osyo). ---------------------------------------- Bug #17013: `RubyVM::AbstractSyntaxTree.parse("struct.field += foo")` has no operator https://bugs.ruby-lang.org/issues/17013 * Author: osyo (manga osyo) * Status: Open * Priority: Normal * ruby -v: ruby 2.8.0dev (2020-07-05T10:15:03Z master 4ea57c2a39) [x86_64-linux] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN ---------------------------------------- ## Summary `RubyVM::AbstractSyntaxTree.parse("struct.field += foo")` has no operator. I'm making a tool that uses AST, but I'm having trouble finding a way to distinguish `struct.field += foo` and `struct.field -= foo` because of this. ## Expected behavior ```ruby node = RubyVM::AbstractSyntaxTree.parse("struct.field += foo") body = node.children.last # have operator (:+) pp body.type # => :OP_ASGN2 pp body.children # => [(VCALL@1:0-1:6 :struct), false, :field, :+, (VCALL@1:16-1:19 :foo)] ``` ## Actual behavior ```ruby node = RubyVM::AbstractSyntaxTree.parse("struct.field += foo") body = node.children.last # have not operator (:+) pp body.type # => :OP_ASGN2 pp body.children # => [(VCALL@1:0-1:6 :struct), false, :field, (VCALL@1:16-1:19 :foo)] ``` Also, `OP_ASGN1` and `LASGN` have operator (`:+`). ``` node = RubyVM::AbstractSyntaxTree.parse("ary[0] += foo") body = node.children.last pp body.type # => :OP_ASGN1 pp body.children # => [(VCALL@1:0-1:3 :ary), :+, (LIST@1:4-1:5 (LIT@1:4-1:5 0) nil), (VCALL@1:10-1:13 :foo)] node = RubyVM::AbstractSyntaxTree.parse("ary += foo") body = node.children.last pp body.type # => :LASGN pp body.children # => [:ary, (CALL@1:0-1:10 (LVAR@1:0-1:3 :ary) :+ (LIST@1:7-1:10 (VCALL@1:7-1:10 :foo) nil))] ``` ## Versions * `ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux]` * `ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]` * `ruby 2.8.0dev (2020-07-05T10:15:03Z master 4ea57c2a39) [x86_64-linux]` ## Patch * PR : https://github.com/ruby/ruby/pull/3294 * Operator position is aligned with `struct.field + = foo` * Operator positions can be changed if desired -- https://bugs.ruby-lang.org/