hugopl / gi-crystal

Tool to generate Crystal bindings for gobject-based libraries (i.e. GTK)
BSD 3-Clause "New" or "Revised" License
45 stars 3 forks source link

User signals with nilable parameters doesn't work. #142

Open hugopl opened 8 months ago

hugopl commented 8 months ago

For the declaration: signal whatever(view : View?)

The generated class_init function is wrong. View | ::Nil.g_type must be View.g_type

def self._class_init(klass : Pointer(LibGObject::TypeClass), user_data : Pointer(Void)) : Nil
  LibGObject.g_signal_new("view_changed", g_type,
  GObject::SignalFlags.flags(RunLast, NoRecurse, NoHooks),
  0,                   # class_offset
  Pointer(Void).null,  # accumulator
  Pointer(Void).null,  # accumulator_data
  Pointer(Void).null,  # marshaller
  GObject::TYPE_NONE,  # return_type
  1, # n_params

  View | ::Nil.g_type,

  Pointer(Void).null)
  previous_def
end
hugopl commented 8 months ago

Issue blocked as well due to a compiler bug, when writing a unit test I get:

Module validation failed: GEP base pointer is not a vector or a vector of pointers
  %11 = getelementptr inbounds %"(Array(Test::Subject+) | GLib::SList(Test::Subject+) | Tuple(Test::Subject+))", %"(Array(Test::Subject+) | GLib::SList(Test::Subject+) | Tuple(Test::Subject+))" %10, i32 0, i32 0, !dbg !10881
GEP base pointer is not a vector or a vector of pointers
  %13 = getelementptr inbounds %"(Array(Test::Subject+) | GLib::SList(Test::Subject+) | Tuple(Test::Subject+))", %"(Array(Test::Subject+) | GLib::SList(Test::Subject+) | Tuple(Test::Subject+))" %10, i32 0, i32 1, !dbg !10881
 (Exception)
  from crystal in '??'
  from crystal in '??'
  from crystal in '??'
  from crystal in '??'
  from crystal in '??'
  from crystal in '??'
  from crystal in '??'
  from crystal in '__crystal_main'
  from crystal in 'main'
  from /usr/lib/libc.so.6 in '??'
  from /usr/lib/libc.so.6 in '__libc_start_main'
  from 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