Crystal: BUG: typeof(item) has no type

Created on 11 Mar 2018  路  5Comments  路  Source: crystal-lang/crystal

I try to write unwrap method but get error

  def unwrap(array)
    result = [] of typeof(array) | typeof(array.first)

    array.each do |item|
      if item.is_a?(Array)
        result = ([] of typeof(item) | typeof(item.first)) + result
        result.concat(item)
      else
        result << item
      end
    end

    result
  end

BUG: typeof(item) has no type

https://play.crystal-lang.org/#/r/3p6i

bug topicsemantic

All 5 comments

Simplified version:

foo = 42
if foo.is_a?(String)
  [] of typeof(foo) | Int32
end

~I think this might be the same problem as #5717.~

This, #7441, and #7461 all seem to be hitting the same piece of code that raises that exception HERE. So all the issues seem to be related in that something is causing @type and @freeze_type to not exist. However, I don't know enough to take a guess as to why :/

This and #7441 are similar and I already have a fix for them. #7461 is different, I need to reduce it more (that means it should be able to be reproducible if you pass --prelude=empty). I will try to do it later if I have time.

Actually this and #7441 are also different :-P

Was this page helpful?
0 / 5 - 0 ratings

Related issues

straight-shoota picture straight-shoota  路  91Comments

ezrast picture ezrast  路  84Comments

malte-v picture malte-v  路  77Comments

sergey-kucher picture sergey-kucher  路  66Comments

asterite picture asterite  路  71Comments