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:
 - Reference.new()

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.
https://play.crystal-lang.org/#/r/ab31
https://play.crystal-lang.org/#/r/ab33

https://play.crystal-lang.org/#/r/ab37

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

1 Like

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.

3 Likes