Wired compiler error, BUG: called type_id for Array(Config)+.class (Crystal::VirtualMetaclassType) (Exception)

I want to refactor my shards to use polydocopt to rewrite the sub-command parser, but when I added this shards into my project, and requireing it, i get following strange compiler error when run shards buld

 ╰──➤ $ shards build
Dependencies are satisfied
Building: new_app
Error target new_app failed to compile:
BUG: called type_id for Array(Config)+.class (Crystal::VirtualMetaclassType) (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 '__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

Following is a reduced reproducible project.

  1. git clone GitHub - zw963/new_app
  2. shards install
  3. shards build

AFAIK, this issue introduced after require docopt shard, but the really issue is:

  1. I can’t understand the error message, the only things i know is, this probably a compiler bug?
  2. Why does the compiler print such a useless log? (Filled with ??, but without source code line number)

Does it work if you make it use GitHub - ralsina/docopt.cr: docopt for crystal-lang via shards override instead of the original? This fork contains some bug fixes that the other shard was doing that was kinda frowned upon.

Usually this means you’re using a production binary that had debug symbols stripped.

1 Like

Thanks, It works after switch to use ralsina/docopt.cr.

But, the issue is, why original version code can broken compiler? a normal compiler error message should not print like this, right?

Related: Why is this failing?. If I had to guess, it’s a different manifestation of why it’s bad to inherit from Array, or other stdlib types.

1 Like

I create a issue on the Github for compiler.

Regardless of how, I believe compiler printing out such a large amount of meaningless log not behavior correct.

As Blacksmoke16 said, this issue caused by inherit from Array, following is the diff screenshot for original old broken version(left) with forked working version(right)

but as a user, we can’t control if one shards use it like that, compiler should tell user what happened instead of many meaningless info.

1 Like