Closed hugopl closed 4 years ago
Ah, well. Minimal example: https://carc.in/#/r/91nz
So the issue is that while for a local variable Crystal can track the possible types pretty well, a instance variable is shared state and could change its value at any point (from another thread). That's why Crystal has to treat it like its class or any subclass.
I'll figure something out to workaround this, probably a distinct to_unsafe
method per parent.
Nice, I was wondering if it was a bug in the compiler, but makes totally sense, as the compiler know all uses of the local variable, it also know the right type at the right moment of it.
The following program fail to compile
It fails with the error:
If I use Gtk::Widget instead of Gtk::Label it fails as well, just the union is bigger with all know widget subclasses.
Expected behavior
Show a small window with a label inside.
Current behavior
It fails to compile.