hugopl / gtk4.cr

GTK4 bindings for Crystal
https://hugopl.github.io/gtk4.cr/
MIT License
101 stars 8 forks source link

`Gtk::CssProvider::ParsingErrorSignal#connect` does not compile #26

Closed BlobCodes closed 2 years ago

BlobCodes commented 2 years ago
css_provider = Gtk::CssProvider.new
css_provider.parsing_error_signal.connect do |section, error|
  # debug
end

This code does not compile with the following error message:

In lib/libadwaita/lib/gi-crystal/src/auto/gtk-4.0/css_provider.cr:198:74

 198 | ::Box(Proc(Gtk::CssSection, GLib::Error, Nil)).unbox(_lib_box).call(section, error)
                                                                      ^---
Error: no overload matches 'Proc(Gtk::CssSection, GLib::Error, Nil)#call' with types Gtk::CssSection, Pointer(Void)

Overloads are:
 - Proc(*T, R)#call(*args : *T)

The generated code:

      def connect(handler : Proc(Gtk::CssSection, GLib::Error, Nil), *, after : Bool = false) : GObject::SignalConnection
        _box = ::Box.box(handler)
        handler = ->(_lib_sender : Pointer(Void), lib_section : Pointer(Void), lib_error : Pointer(Void), _lib_box : Pointer(Void)) {
          # Generator::BuiltInTypeArgPlan
          section = Gtk::CssSection.new(lib_section, :none)
          error = lib_error
          ::Box(Proc(Gtk::CssSection, GLib::Error, Nil)).unbox(_lib_box).call(section, error)
        }.pointer

        handler = LibGObject.g_signal_connect_data(@source, name, handler,
          GICrystal::ClosureDataManager.register(_box), ->GICrystal::ClosureDataManager.deregister, after.to_unsafe)
        GObject::SignalConnection.new(@source, handler)
      end

GI-Crystal version: 0.12.0 Crystal version: 1.4.1

BlobCodes commented 2 years ago

I should add that this used to work in an older version of GI-Crystal

hugopl commented 2 years ago

I see the issue.... there's no ArgPlan for error parameters, so it's just using the same value without any conversion, like it does for Int32 and other basic types.

hugopl commented 2 years ago

I took a look on this, the proper fix isn't soooo simple, because the proper fix need to make the signal parameters arrive as a exception class translated from the GError, not GLib::Error, in fact GLib::Error shouldn't exist as a wrapper of GError, but as a base class for all exceptions generated from GError.

i.e. GError must be tagged as a hand made type on bindings.yml, but the current implementation of handmade type is too open due to GValue implementation, so I need to re-think a bit how to deal with these handmade types.