Hello,
Should the following code snippet work? The error message is:
Error: no overload matches 'Pointer(Int32)#copy_from_impl' with types Pointer(String), Int32
Which indicates that the first is_a?
isn’t really restricting the type for the pointerof(v)
call.
class Test
@a = Pointer(Int32).malloc(1)
@b = Pointer(UInt8).malloc(10)
def set(v : Int32 | String)
if v.is_a?(Int32)
pointerof(v).copy_to(@a, 1)
elsif v.is_a?(String)
v.to_unsafe.copy_to(@b, val.bytesize)
end
end
end
Test.new.set("hello")
Thanks