Issue #18040 has been updated by jeremyevans0 (Jeremy Evans).

Backport deleted (2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN)
Tracker changed from Bug to Feature

`1 if true` is a statement and not an expression, and you can only pass expressions as method arguments. `(1 if true)` is an expression, which is why it is allowed. Consider how `foo(1 if true)` would work with multiple arguments, and you can probably figure out what the problems are. Note that `foo (1 if true)` (with a space) works, since that's a method call without parentheses,  with a single argument of `(1 if true)`.

This isn't a bug, it's expected behavior.  I'm not sure whether changing the grammar to support this type of one argument method call is possible, but I'm guessing @nobu would know best.  In any case, adding support for this would be a feature request.

----------------------------------------
Feature #18040: Why should `foo(1 if true)` be an error?
https://bugs.ruby-lang.org/issues/18040#change-92953

* Author: bughit (bug hit)
* Status: Open
* Priority: Normal
----------------------------------------
There's no ambiguity here that should require another set of parens `foo((1 if true))`



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>