[ruby-core:93576] [Ruby master Bug#15990] "else if" causes confusing syntax error

From: shevegen@...
Date: 2019-07-06 07:34:55 UTC
List: ruby-core #93576
Issue #15990 has been updated by shevegen (Robert A. Heiler).


I guess it should be possible to distinguish between "else if" and "elsif"
by the ruby parser already, since it does fail if the 'e ' part is there
in the first case, as otherwise the parser would accept the syntax. So I
think it would be possible to change the error message without too much
difficulty. Whether that ought to happen or not is, in my opinion, up to
matz and the core team e. g. whether they want to have a different message
show up here. I personally don't mind either way.

What I think has not yet been described is: what message would you recommend
to appear other than the current one? This may help matz and/or the ruby
core team to decide how useful the proposed change may be. Newcomers are of
course one target audience, but so are other ruby users; so the new error
message, if decided to make a change, should cover useful cases for both
groups of ruby users.

----------------------------------------
Bug #15990: "else if" causes confusing syntax error
https://bugs.ruby-lang.org/issues/15990#change-79156

* Author: viko (Viko Viko)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18]
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
```
if false
  puts 'false'
else if true
  puts 'true'
end
```

This fails with "syntax error: unexpected end-of-input, expecting end". `else if` isn't `elsif`, of course, but if a file contains `else if` (especially on one line, though I don't know how easy that would be to track) and fails to parse, it is probably worth noting, especially since this kind of syntax error can't easily be traced back to a particular line.



-- 
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>

In This Thread

Prev Next