```
Module validation failed: Invalid bitcast
%4 = bitcast i32* %3 to %"(Spectator::Arguments(T, NT) | Nil)", !dbg !16
(Exception)
from /crystal/src/int.cr:541:9 in 'finish'
from /crystal/src/compiler/crystal/codegen/codegen.cr:71:7 in 'codegen'
from /crystal/src/compiler/crystal/compiler.cr:173:16 in 'compile'
from /crystal/src/compiler/crystal/command/spec.cr:98:14 in 'spec'
from /crystal/src/hash.cr:901:11 in '__crystal_main'
from /crystal/src/crystal/main.cr:115:5 in 'main'
from src/env/__libc_start_main.c:94:2 in 'libc_start_main_stage2'
Error: you've found a bug in the Crystal compiler. ...
```
I haven't been able to reproduce this in a simplified form.
Passing the `constraint` argument in NullStub#and_return to ValueStub.new triggers the bug.
Removing the `constraint` argument fixes the issue.
Somewhere along the way the block argument gets dropped.
Even though `method` is a `Def` that accepts a block, the `&block` portion is dropped.
Possible Crystal compiler bug.
For some reason, attempting to get the class of the stubbed value causes a segfault.
This appears to get swallowed in some cases.
Trying to inspect the value was difficult without triggering some error.
In the failing case, the value is 42 (returned by a stubbed foo method).
The method is supposed to return a String, and this error checking should be triggered (line 119).
The value is a union, and inspecting the bytes contained in it looks like it's prefixed with the Crystal type ID for Int32.
However it looks like Crystal tries to treat it as a Bool? I'm not sure.
Very weird behavior and instead of wasting more time on it, I'm omitting the returned type from the error.
This type of casting error shouldn't be common.
This seems like a Crystal bug, but I'm having a hard time distilling the issue.