The following code has invalid syntax:
# bad_code.rb
def foo
next
end
$ ruby bad_code.rb
bad_code.rb:2: Invalid next
bad_code.rb: compile error (SyntaxError)
However, running ruby -c bad_code.rb
doesn't detect any problems:
$ ruby -c bad_code.rb
Syntax OK
Yet ruby -c
is supposed to be for checking syntax:
-c check syntax only
Why isn't it detecting this error?
rubocop bad_code.rb
also doesn't detect this:
$ rubocop bad_code.rb
Inspecting 1 file
.
1 file inspected, no offenses detected
I ran this on Ruby 2.1.10.
It is syntactically correct, but when the ruby interpreter tries to produce code for it, it recognizes that there is no target for the next
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With