I guess I have not understood how do deal with Union Types.
Please have a look to the following code:
class Weird property val : Int32 | Nil def initialize @val = nil end def initialize(@val) end def add(n : Int32) if !@val @val = 0 end @val += n end end a = Weird.new 9 a.add(19)
val can either be Nil or an Int32
In the add method I wanted to add n to val after I initialized val to 0.
Unfortunately the compiler says: undefined method ‘+’ for Nil (compile-time type is (Int32 | Nil))
I have no clue how to solve that.