Project

General

Profile

Actions

Bug #21984

open

RubyVM::AST can't tell if an array is passed to break/next/return

Bug #21984: RubyVM::AST can't tell if an array is passed to break/next/return

Added by kddnewton (Kevin Newton) about 18 hours ago. Updated about 6 hours ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:125208]

Description

irb(main):005> RubyVM::AbstractSyntaxTree.parse("tap { break [1, 2, 3] }")
=> (SCOPE@1:0-1:23 tbl: [] args: nil body: (ITER@1:0-1:23 (FCALL@1:0-1:3 :tap nil) (SCOPE@1:4-1:23 tbl: [] args: nil body: (BREAK@1:6-1:21 (LIST@1:12-1:21 (INTEGER@1:13-1:14 1) (INTEGER@1:16-1:17 2) (INTEGER@1:19-1:20 3) nil)))))
irb(main):006> RubyVM::AbstractSyntaxTree.parse("tap { break 1, 2, 3 }")
=> (SCOPE@1:0-1:21 tbl: [] args: nil body: (ITER@1:0-1:21 (FCALL@1:0-1:3 :tap nil) (SCOPE@1:4-1:21 tbl: [] args: nil body: (BREAK@1:6-1:19 (LIST@1:12-1:19 (INTEGER@1:12-1:13 1) (INTEGER@1:15-1:16 2) (INTEGER@1:18-1:19 3) nil)))))
irb(main):007> 

The issue is, break [1, 2, 3] has the same AST as break 1, 2, 3 (presumably because they are effectively the same thing). But a consumer has no way to know if an array was used short of re-parsing the source.

Actions

Also available in: PDF Atom