[ruby-core:96110] [Ruby master Bug#16389] Unexpected tINTEGER in conditional expression

[email protected]
Newsgroups gmane.comp.lang.ruby.core
Message-ID <redmine.journal-82969.20191204161030.a7f13e187fd5c855@ruby-lang.org>
Issue #16389 has been updated by codinganarchy (Matthew Tanous).


mame (Yusuke Endoh) wrote:
> I don't think that your expectation is wrong, but due to parser limitation, we cannot place a non-parenthesized method call as an argument of `&&`.  It is a good practice to write parentheses for method calls, except some trivial cases (e.g., no-argument method calls and `p arg`).

Just to clarify, if you don't mind, is this also due to the difference between `.>` (a method) and `>` (an operator)? I ask as `foo unless (@bar&.nil? && @baz > 15)` does not result in a syntax error, though using `&& @baz.> 15` will.



----------------------------------------
Bug #16389: Unexpected tINTEGER in conditional expression
https://bugs.ruby-lang.org/issues/16389#change-82969

* Author: codinganarchy (Matthew Tanous)
* Status: Rejected
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.4p104 (2019-08-28 revision 67798) [x86_64-darwin18]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
I'm not sure that this is a bug, or simply an unexpected result of operator precedence, but I am seeing a result that appears to me to be an issue.

When putting a conditional expression after a command call using `unless`, I am seeing a syntax error when I believe the syntax should be valid. In particular:

```ruby
def foo
    puts "This method just has to exist"
end

foo unless (@bar&.nil? && @baz&.> 15)
```

This produces`syntax error, unexpected tINTEGER, expecting ')'`  following the `&.>` safe navigation. I would not expect a syntax error here.

This seems a strange result to me, as `foo unless (@bar&.nil? and @baz&.> 15)` appears to work as expected, producing no syntax error.

Please let me know if I am missing something in either my expectation or the issue report. Thanks!





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

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.