Slice union type puts exception

Is this a bug? puts exception occurs only when I have union slice type

a = Slice(Int32|UInt8).new(4)
a[0] = 1
a[1] = 2
puts a     #=> exception

OP:

Slice[1, 2, Unhandled exception: Arithmetic overflow (OverflowError)
  from /usr/share/crystal/src/enumerable.cr:445:9 in 'to_s'
  from /usr/share/crystal/src/io.cr:174:5 in '<<'
  from /usr/share/crystal/src/io.cr:231:5 in 'puts'
  from /usr/share/crystal/src/kernel.cr:388:3 in 'puts'
  from code93.cr:4:1 in '__crystal_main'
  from /usr/share/crystal/src/crystal/main.cr:110:5 in 'main_user_code'
  from /usr/share/crystal/src/crystal/main.cr:96:7 in 'main'
  from /usr/share/crystal/src/crystal/main.cr:119:3 in 'main'
  from __libc_start_main
  from _start
  from ???

Sure looks like a bug. I suppose the issue is that the overload Slice.new(Int) should not be acceptable for a union of primitive types.

got it, sure, i will file a minor bug then. thanks

1 Like