From: mame@... Date: 2019-08-09T14:48:15+00:00 Subject: [ruby-core:94224] [Ruby master Bug#16092] [doc] precedence of modifier-rescue Issue #16092 has been updated by mame (Yusuke Endoh). Status changed from Open to Rejected The current doc about precedence is correct. The behavior you showed is not caused by precedence, but by the grammer itself. The point is, that ` rescue ` is a statement, not an expression. The right side of modifier-if must be an expression, so ` rescue ` cannot be a right side of modifier-if. So, ` if rescue ` can parse only as `( if ) rescue `. `defined?` also requires an expression as its argument. So `defined? expr rescue $!` can parse only as `defined? (expr rescue $!)`. You can see the precedence by the following code: `stmt if v = condition rescue $!`. It can parse as both `(stmt if v = condition) rescue $!` and `stmt if v = (condition rescue $!)` but the second one is chosen because modifier-rescue has higher precedence than modifier-if. ---------------------------------------- Bug #16092: [doc] precedence of modifier-rescue https://bugs.ruby-lang.org/issues/16092#change-80523 * Author: Dan0042 (Daniel DeLorme) * Status: Rejected * Priority: Normal * Assignee: * Target version: * ruby -v: * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN ---------------------------------------- The docs state that modifier-rescue has lower precedence than assignments which have lower precedence than modifier-if. This is true for `v = expr rescue $! if condition` but not for `v = expr if condition rescue $!` which is treated as `(v = expr if condition) rescue $!` rather than `v = expr if (condition rescue $!)` This goes similarly for `defined? expr rescue $!` `not expr rescue $!` `expr1 and expr2 rescue $!` `expr1 or expr2 rescue $!` So maybe the documentation should state that modifier-rescue has **equal** precedence to modifier-if & others, with an **exception** made for assignments? I'm not entirely sure how to describe that exception though. -- https://bugs.ruby-lang.org/ Unsubscribe: