You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An attempt to use Tree#sum results in the following error:
can't infer block return type, try to cast the block body with `as`. See: https://github.com/crystal-lang/crystal/wiki/Compiler-error-messages#cant-infer-block-return-type
@value + @children.each.map(&.sum).sum
^~~
We can fix it by doing what the compiler suggests, that is be replacing map(&.sum) with
map { |child| child.sum.as(Int32) }
However, this seems completely unnecessary - the type of Tree#sum is specified as Int32, so the compiler has nothing to infer and the cast should do nothing.
The text was updated successfully, but these errors were encountered:
Consider the following snippet:
An attempt to use
Tree#sum
results in the following error:We can fix it by doing what the compiler suggests, that is be replacing
map(&.sum)
withHowever, this seems completely unnecessary - the type of
Tree#sum
is specified asInt32
, so the compiler has nothing to infer and the cast should do nothing.The text was updated successfully, but these errors were encountered: