Project

General

Profile

Actions

Bug #22450

closed

Jump value attaches block in incorrect place under parse.y

Bug #22450: Jump value attaches block in incorrect place under parse.y

Added by kddnewton (Kevin Newton) 5 days ago. Updated 4 days ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:127140]

Description

Sorry about this one. The following code: check 1, if true then return foo + bar do end end under Prism:

-e: warning: argument of top-level return is ignored
== disasm: #<ISeq:<main>@-e:1 (1,0)-(1,49)>
0000 putself                                                          (   1)[Li]
0001 putobject_INT2FIX_1_
0002 adjuststack                            2
0004 putself
0005 opt_send_without_block                 <calldata!mid:foo, argc:0, FCALL|VCALL|ARGS_SIMPLE>
0007 putself
0008 send                                   <calldata!mid:bar, argc:0, FCALL>, block in <main>
0011 opt_plus                               <calldata!mid:+, argc:1, ARGS_SIMPLE>[CcCr]
0013 leave                                  [Re]
0014 putnil
0015 opt_send_without_block                 <calldata!mid:check, argc:2, FCALL|ARGS_SIMPLE>
0017 leave

== disasm: #<ISeq:block in <main>@-e:1 (1,39)-(1,45)>
0000 putnil                                                           (   1)[Bc]
0001 leave                                  [Br]

but under parse.y:

-e: warning: argument of top-level return is ignored
== disasm: #<ISeq:<main>@-e:1 (1,0)-(1,49)>
0000 putself                                                          (   1)[Li]
0001 putobject_INT2FIX_1_
0002 adjuststack                            2
0004 putself
0005 opt_send_without_block                 <calldata!mid:foo, argc:0, FCALL|VCALL|ARGS_SIMPLE>
0007 putself
0008 opt_send_without_block                 <calldata!mid:bar, argc:0, FCALL|VCALL|ARGS_SIMPLE>
0010 send                                   <calldata!mid:+, argc:1>, block in <main>
0013 leave                                  [Re]
0014 putnil
0015 opt_send_without_block                 <calldata!mid:check, argc:2, FCALL|ARGS_SIMPLE>
0017 leave

== disasm: #<ISeq:block in <main>@-e:1 (1,39)-(1,45)>
0000 putnil                                                           (   1)[Bc]
0001 leave                                  [Br]

The block is getting attached to the + operation. I think the problem with this is that when a block is found after a jump, parse.y blindly attaches the block to whatever it finds in the value position.

Updated by nobu (Nobuyoshi Nakada) 4 days ago Actions #1

  • Backport changed from 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN to 3.3: REQUIRED, 3.4: REQUIRED, 4.0: REQUIRED

Updated by nobu (Nobuyoshi Nakada) 4 days ago Actions #2

  • Status changed from Open to Closed

Applied in changeset git|31a3aa4e46dd33b5a08708d687ed9f9d3253b55a.


[Bug #22450] Preserve do-block binding in control-flow arguments

Inherited CMDARG state made do blocks in control-flow arguments
bind to the wrong call.

Actions

Also available in: PDF Atom