Virtual functions that return nullable objects fail to compile
Closed this issue · 0 comments
hugopl commented
Gio::ListModel
has a virtual function called get_item
that returns an GObject::Object
or nil
, however if the code returns nil it fails to compile:
There was a problem expanding macro '_register_get_item_vfunc'
Code in macro 'method_added'
5 | _register_get_item_vfunc(get_item)
^
Called macro defined in lib/gi-crystal/src/auto/gio-2.0/list_model.cr:72:13
72 | private macro _register_get_item_vfunc(impl_method_name)
Which expanded to:
> 10 |
> 11 | __temp_70 = __temp_69.as(self).get_item(position)
> 12 | __temp_70.to_unsafe
^--------
Error: undefined method 'to_unsafe' for Nil (compile-time type is (Doc | Nil))
In my code, Doc
was a class that inherits GObject::Object
.