Bug #20731
closedwarning: mismatched indentations at 'when' appears with prism enabled ruby
Description
Steps to reproduce¶
- Create a
case_sample.rb
file
foo = :bar
case foo
when :bar
p 'foo is :bar'
when :baz
# do something
else
# do something
end
- Run this file against the latest Ruby 3.4.0dev with -w option to show warnings
$ ruby -w case_sample.rb
Expected behavior¶
It should show "foo is :bar"
without any warnings as it runs against Ruby 3.3.5 or Ruby 3.4.0dev before prism is used by default
$ ruby -w case_sample.rb
"foo is :bar"
$ ruby -v
ruby 3.3.5 (2024-09-03 revision ef084cc8f4) [x86_64-linux]
$
$ ruby -w case_sample.rb
"foo is :bar"
$ ruby -v
ruby 3.4.0dev (2024-09-12T17:04:10Z master f2919bd11c) [x86_64-linux]
$
Actual behavior¶
It raises warning: mismatched indentations at 'when' with 'case'
warnings as follows.
$ ruby -w case_sample.rb
case_sample.rb:3: warning: mismatched indentations at 'when' with 'case' at 2
case_sample.rb:5: warning: mismatched indentations at 'when' with 'case' at 2
"foo is :bar"
$ ruby -v
ruby 3.4.0dev (2024-09-12T20:03:28Z master 0fc8422a05) +PRISM [x86_64-linux]
$
Background¶
This repro is based on the tzinfo code below.
https://github.com/tzinfo/tzinfo/blob/d5893c99bbcd842af86023f02a84fac1659b3031/lib/tzinfo/timestamp.rb#L115-L127
https://github.com/tzinfo/tzinfo/blob/d5893c99bbcd842af86023f02a84fac1659b3031/lib/tzinfo/timestamp.rb#L147-L154
Updated by hsbt (Hiroshi SHIBATA) about 2 months ago
I also have similar issues with rss
.
/Users/hsbt/Documents/github.com/ruby/ruby/gems/src/rss/lib/rss/1.0.rb:81: warning: mismatched indentations at ‘else’ with ‘if’ at 79
(snip)
https://github.com/ruby/rss/blob/master/lib/rss/1.0.rb#L81 is seems correct for me.
Updated by mame (Yusuke Endoh) about 2 months ago
The wrong warning with rss
gem is a different issue. I have created a separate ticket #20732.
Updated by hsbt (Hiroshi SHIBATA) about 2 months ago
Thanks!
Updated by hsbt (Hiroshi SHIBATA) about 2 months ago
- Status changed from Open to Assigned
- Assignee set to kddnewton (Kevin Newton)
Updated by kddnewton (Kevin Newton) about 2 months ago
I have opened https://github.com/ruby/ruby/pull/11620 to fix this.
Updated by kddnewton (Kevin Newton) about 2 months ago
- Status changed from Assigned to Closed