Feature #5716
closedduplicated when clause is ignored -> Report which clause it is specifically.
Description
In latest Ruby 1.9.3, if you have warnings enabled, you get information like this here:
foobar.rb:24: warning: duplicated when clause is ignored
This error comes from the file:
compile.c
rb_compile_warning(RSTRING_PTR(iseq->filename), iobj->line_no,
"duplicated when clause is ignored");
This is called, it seems, when the prior function fails:
rb_hash_aset(map, obj, INT2FIX(lobj->position - (pos+len)));
As a user of Ruby, the warning should be better.
Rather than:
foobar.rb:24: warning: duplicated when clause is ignored
I would like to see:
foobar.rb:24: warning: duplicated when clause 'foo' is ignored.
This way, I can scan through the file with the case/when structure
and correct this error. But right now, if you have a very long
case/when structure, you have no idea WHICH clause is duplicated.
The warning message just vaguely says that there is, and this is
not very helpful information.
Updated by mame (Yusuke Endoh) about 12 years ago
- Status changed from Open to Assigned
- Assignee set to ko1 (Koichi Sasada)
Updated by ko1 (Koichi Sasada) about 12 years ago
Thank you for your comment.
I added a small hint on it because if duplicated object was too big, the
output should be ugly.
Does it help you?
sample code¶
case nil
when 1
when 1, 1
when 1, 1, 1, 1
when 1, 1
end
#=>
../trunk/test.rb:1: warning: duplicated when clause (#1) is ignored
../trunk/test.rb:1: warning: duplicated when clause (#2) is ignored
../trunk/test.rb:1: warning: duplicated when clause (#3) is ignored
../trunk/test.rb:1: warning: duplicated when clause (#4) is ignored
../trunk/test.rb:1: warning: duplicated when clause (#5) is ignored
../trunk/test.rb:1: warning: duplicated when clause (#6) is ignored
../trunk/test.rb:1: warning: duplicated when clause (#7) is ignored
../trunk/test.rb:1: warning: duplicated when clause (#8) is ignored
Patch:
Index: compile.c
--- compile.c (revision 35267)
+++ compile.c (working copy)
@@ -1454,8 +1454,9 @@
rb_hash_aset(map, obj, INT2FIX(lobj->position - (pos+len)));
}
else {
-
int n = i/2; rb_compile_warning(RSTRING_PTR(iseq->filename), iobj->line_no,
-
"duplicated when clause is ignored");
-
"duplicated when clause (#%d) is ignored", n); } } hide_obj(map);
(2011/12/06 19:07), markus heiler wrote:
Issue #5716 has been reported by markus heiler.
Feature #5716: duplicated when clause is ignored -> Report which clause it is specifically.
http://redmine.ruby-lang.org/issues/5716Author: markus heiler
Status: Open
Priority: Low
Assignee:
Category:
Target version:In latest Ruby 1.9.3, if you have warnings enabled, you get information like this here:
foobar.rb:24: warning: duplicated when clause is ignored
This error comes from the file:
compile.c
rb_compile_warning(RSTRING_PTR(iseq->filename), iobj->line_no,
"duplicated when clause is ignored");This is called, it seems, when the prior function fails:
rb_hash_aset(map, obj, INT2FIX(lobj->position - (pos+len)));
As a user of Ruby, the warning should be better.
Rather than:
foobar.rb:24: warning: duplicated when clause is ignored
I would like to see:
foobar.rb:24: warning: duplicated when clause 'foo' is ignored.
This way, I can scan through the file with the case/when structure
and correct this error. But right now, if you have a very long
case/when structure, you have no idea WHICH clause is duplicated.The warning message just vaguely says that there is, and this is
not very helpful information.
--
// SASADA Koichi at atdot dot net
Updated by shevegen (Robert A. Heiler) about 12 years ago
Hi Koichi Sasada!
I have not tested it yet (will do so at the end of this week),
but I believe it will help me.
Thank you! :)
Updated by ko1 (Koichi Sasada) about 12 years ago
- Status changed from Assigned to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r35277.
markus, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
- compile.c (iseq_set_sequence): show a hint if there are duplicated
"when" clauses. [ruby-core:41502] [ruby-trunk - Feature #5716]