Project

General

Profile

Bug #8279

Single-line rescue parsing

Added by dunric (David Unric) over 6 years ago. Updated 3 months ago.

Status:
Closed
Priority:
Normal
Target version:
-
ruby -v:
2.0.0p0
Backport:
[ruby-core:54338]

Description

Hi,

there seems to be a bug in parser for single-line rescue statement. It fails in case of multiple assignment statements, keeping operator precedence vs. simple assignment etc.

obj = expression rescue objval

parsed as

obj = (expression rescue objval)

obj1, obj2 = expression rescue [objval1, objval2]

parsed as

(obj1, obj2 = expression) rescue [objval1, objval2]

obj += expression rescue objval

parsed as

obj += (expression rescue objval)

obj = obj + expression rescue objval

parsed as

obj = (obj + expression) rescue objval

There is already a thread about this issue on ruby-forum.com, even Matz himself is aware and did gave a nod to this problem http://www.ruby-forum.com/topic/152260#671711 , though nothing was done to fix it yet.

I've tried to report about this problem once (http://bugs.ruby-lang.org/issues/8239) but it was ignored for no known reason.


Files

massign-rescue-modifier-8279.patch (2.08 KB) massign-rescue-modifier-8279.patch jeremyevans0 (Jeremy Evans), 08/09/2019 03:10 AM

Related issues

Is duplicate of Ruby master - Feature #8239: Inline rescue bugClosedActions

Associated revisions

Revision 53b3be5d
Added by jeremyevans (Jeremy Evans) 3 months ago

Fix parsing of mutiple assignment with rescue modifier

Single assignment with rescue modifier applies rescue to the RHS:

a = raise rescue 1 # a = (raise rescue 1)

Previously, multiple assignment with rescue modifier applied rescue
to the entire expression:

a, b = raise rescue [1, 2] # (a, b = raise) rescue [1, 2]

This makes multiple assignment with rescue modifier consistent with
single assignment with rescue modifier, applying rescue to the RHS:

a, b = raise rescue [1, 2] # a, b = (raise rescue [1, 2])

Implements [Feature #8239]
Fixes [Bug #8279]

History

Updated by nobu (Nobuyoshi Nakada) over 6 years ago

  • Priority changed from 5 to Normal

Updated by jeremyevans0 (Jeremy Evans) 3 months ago

This bug is still present in the master branch. Attached is a patch that fixes it, so that multiple assignment with rescue modifier is consistent with single assignment with rescue modifier. After the patch:

a = raise rescue 1 # a = (raise rescue 1)
a, b = raise rescue [1, 2] # a, b = (raise rescue [1, 2])

Updated by nobu (Nobuyoshi Nakada) 3 months ago

Thank you, it seems fine. I've missed this at all.

#4

Updated by jeremyevans (Jeremy Evans) 3 months ago

  • Status changed from Open to Closed

Applied in changeset git|53b3be5d58a9bf1efce229b3dce723f96e820c79.


Fix parsing of mutiple assignment with rescue modifier

Single assignment with rescue modifier applies rescue to the RHS:

a = raise rescue 1 # a = (raise rescue 1)

Previously, multiple assignment with rescue modifier applied rescue
to the entire expression:

a, b = raise rescue [1, 2] # (a, b = raise) rescue [1, 2]

This makes multiple assignment with rescue modifier consistent with
single assignment with rescue modifier, applying rescue to the RHS:

a, b = raise rescue [1, 2] # a, b = (raise rescue [1, 2])

Implements [Feature #8239]
Fixes [Bug #8279]

Also available in: Atom PDF