The Crystal Programming Language Forum

Complex case statments

I am having trouble with some case statements and have tried to reduce the statements down for a bug but then they seem to work. Am I missing something simple?

Here is the case statement that is not compiling.

This fails with the error.

Error: no argument named 'amount'

Matches are:

All three operations have an initializer with and amount argument.

Here is an overly reduced example one with arguments and one without. Both seem to work.

Issue seems to be when there is another subclass that isn’t accounted for in the case.

Oh wow thanks for figuring that out. Is this something already known by the core team?

For reference: Discussion continued on the issue tracker in Case with subclasses not working · Issue #10292 · crystal-lang/crystal · GitHub

TLDR; The behaviour is expected, but the error message is terrible.