class Foo
@x : Int64 = 10 # OK, 10 fits in an Int64
def set_x(y)
@x = y
end
end
Foo.new.set_x 1 # Error: "at line 5: instance variable '@x' of Foo must be Int64, not Int32"
but the program runs just fine now, does anything changes between versions?
Ah okay, then yea the linked PR seemed to have changed that. Documentation probably needs updated to reflect it. Mind filing an issue on the crystal-book repo?
Anyway, i consider this flag (by default, enabled currently) probably cause some run-time error.
class Foo
@x : Int32 = 10 # OK, 10 fits in an Int64
def set_x(y)
@x = y
end
end
Foo.new.set_x Int32::MAX + 1
Unhandled exception: Arithmetic overflow (OverflowError)
from 1.cr:9:26 in ‘__crystal_main’
from /home/zw963/Crystal/share/crystal/src/crystal/main.cr:129:5 in ‘main_user_code’
from /home/zw963/Crystal/share/crystal/src/crystal/main.cr:115:7 in ‘main’
from /home/zw963/Crystal/share/crystal/src/crystal/main.cr:141:3 in ‘main’
from /usr/lib/libc.so.6 in ‘??’
from /usr/lib/libc.so.6 in ‘__libc_start_main’
from /home/zw963/.cache/crystal/crystal-run-1.tmp in ‘_start’
from ???