stumpy_core
stumpy_core copied to clipboard
Fix equality for non-canvas objects
In the current master branch, the following produces a compiler error:
require "stumpy_core"
canvas = StumpyCore::Canvas.new(10, 10)
canvas == "test"
The error occurs inside StumpyCore::Canvas#==(other) as such:
Showing last frame. Use --error-trace for full trace.
In src/stumpy_core/canvas.cr:184:25
184 | @width == other.width &&
^----
Error: undefined method 'width' for String
This is because the class checking done in the existing == method does not actually restrict the type of other before using Canvas-specific properties (code link)
I fixed the bug using an overload (Which seems to be the standard method of doing so), and added specs.