The Crystal Programming Language Forum

Type inference doesn't work inside ternary operator

array = Array(Int8).new(5, 0)

i_am_true = true

# this will error
#array[2] = (i_am_true ? 1 : 0)  

# this works
#array[2] = (i_am_true ? 1_i8 : 0_i8)  

# this works
array[2] = 1

pp array
array.each do |a|
  pp typeof(a)
end

Bug or intended?

limitation of the autocasting feature https://github.com/crystal-lang/crystal/pull/6074

2 Likes

I see. Thanks

Btw, the PR title “Explosive birth” is amazing :grin: