Open zw963 opened 1 year ago
You're comparing against Nil
the class, not nil
the type.
Nevermind, it seems to expand to the class either way.
Object#===(other)
is defined for every argument type (it just returns false
by default). It's not expected to be type-save. And so must Range#===(other)
.
Fixing the generic implementation is a bit tricky, though. It needs to check whether the comparison between other
and begin
/end
are allowed.
Bug Report
For more details, check discuss on https://forum.crystal-lang.org/t/in-case-statement-case-nil-and-range/2623/2
Following code not work on Crystal 1.7.2
Click me to see back trace
``` In 1.cr:13:6 13 | when 'A'..'Z' ^- Error: instantiating 'Range(Char, Char)#===(Nil)' In /home/zw963/Crystal/share/crystal/src/range.cr:327:5 327 | includes?(value) ^-------- Error: instantiating 'includes?(Nil)' In /home/zw963/Crystal/share/crystal/src/range.cr:298:32 298 | (begin_value.nil? || value >= begin_value) && ^ Error: undefined method '>=' for Nil Nil trace: /home/zw963/Crystal/share/crystal/src/range.cr:298 (begin_value.nil? || value >= begin_value) && /home/zw963/Crystal/share/crystal/src/range.cr:293 def includes?(value) : Bool ```Fix is simple, just swap the position.