BUG: trying to downcast TCPSocket+ (Crystal::VirtualType) <- TCPSocket (Crystal::NonGenericClassType)

Hi, i get an unable to understand compiler output again.

Error target procodile failed to compile:
BUG: trying to downcast TCPSocket+ (Crystal::VirtualType) <- TCPSocket (Crystal::NonGenericClassType) (Exception)
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '??'
  from /home/zw963/Crystal/bin/crystal in '__crystal_main'
  from /home/zw963/Crystal/bin/crystal in 'main'
  from /usr/lib/libc.so.6 in '??'
  from /usr/lib/libc.so.6 in '__libc_start_main'
  from /home/zw963/Crystal/bin/crystal in '_start'
  from ???
Error: you've found a bug in the Crystal compiler. Please open an issue, including source code that will allow us to reproduce the bug: https://github.com/crystal-lang/crystal/issues

You can reproduce this issue on add_proxy_feature_back branch of procodile_cr

1. git clone https://github.com/crystal-china/procodile_cr.git
2.  cd procodile_cr
3. git checkout add_proxy_feature_back
4.  git reset --hard 8a3de19   # only if current git hash is not same
5. shards build

It’s seem like issue raised from a very unexpected place by this code, but, i have no idea of what happens

More context: current branch is adding the missing proxy feature back to Crystal fork. (reference original Ruby version code), it still WIP and not work anyway, but the really issue is, give me this error message is really useless for developer understand what happens.

Thanks.

Is there a reason you need to sleep here? This may be considered sloppy depending on who you ask.

This is a bug, however, I find one line particularly interesting:

I have never seen rescue used like this and it’s not even documented in Exception handling - Crystal

Is it possible the bug comes from that? Try using begin..end instead and see if that helps?

Yes, it is probably not documented, but it is quite common usage when write Ruby, it works too with Crystal.

Is there a reason you need to sleep here?

No, i remove it.

Is it possible the bug comes from that?

No, after i reduce the code, i found this exception come from a very unexpected place.

Please pull the latest 8a3de19 on add_proxy_feature_back branch to reproduce this.