forked from crystal-lang/crystal
-
Notifications
You must be signed in to change notification settings - Fork 0
Compiler error messages
Ary Borenszweig edited this page Jan 27, 2015
·
1 revision
For example:
class Foo
def initialize(@name)
end
def name
@name
end
end
a = [] of Foo
x = a.map { |f| f.name } #=> error: can't infer block type, try to cast the block body with `as`Here Foo was never instantiated so the compiler has no way of knowing what the type of @name is.
To solve this, cast the block body with as:
x = a.map { |f| f.name as String } # worksIn the future we want to get rid of this error messages and make the compiler smarter. In the above case @name could be deduced to be Void or NoReturn, but for now you have to use this workaround.