Feature #16755
openwarning: `if' at the end of line without an expression
Description
I'm using this notation in a lot of scripts:
if
true
then
puts :a
else
puts :b
end
Using ruby 2.6.5 I'm getting expected response:
(0) 2.6.5 mpapis@mpapis-linux:~/tmp>ruby -w test.rb
a
Using ruby 2.7.1 I'm getting extra warning:
(0) 2.7.1 mpapis@mpapis-linux:~/tmp>ruby -w test.rb
test.rb:1: warning: `if' at the end of line without an expression
a
I've tracked it to the following git commits:
- ba35c14325ebbf1da8f200df83c45ee9937ff8a1
- c303854e134043d905baff2385add44cc2c28756
- 26316cc350109ba71d42f944f3b976985627c042
- e91e3274bebc803b97971ad0a6f4ee3a8c646a60
- a087e027bf7cf0fbb825f1d55668f85ab1f3c9e6
- 30a74aaef00a99364f5423439ac44babf5066dc0
Updated by jeremyevans0 (Jeremy Evans) over 4 years ago
- ruby -v deleted (
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]) - Backport deleted (
2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN) - Tracker changed from Bug to Feature
As you can see from the commit message in ba35c14325ebbf1da8f200df83c45ee9937ff8a1, this is a new feature and expected behavior in Ruby 2.7, though it may still be considered experimental.
You can filter the warnings by overriding Warning.warn
, or using the warning gem:
require 'warning'
Warning.ignore(/`(els)?if' at the end of line without an expression/)
As the current behavior is now expected, this isn't a bug, so I'm switching this to a feature request to remove the warning.
Updated by shevegen (Robert A. Heiler) over 4 years ago
You can filter the warnings by overriding Warning.warn, or using the warning gem:
require 'warning'
Warning.ignore(/`(els)?if' at the end of line without an expression/)
That's pretty cool! I did not know that was possible in quite that way. Learned
something there. :D
[Removed stuff here.]
Edit: Aaah yikes ... I misread your comment; you referred to the warning gem. I
thought this was part of ruby as-is. Well, still cool that this exists at the
least.