jhass / crystal-gobject

gobject-introspection for Crystal
BSD 3-Clause "New" or "Revised" License
127 stars 13 forks source link

Error: method GdkPixbuf::Pixbuf.new_from_stream must return GdkPixbuf::Pixbuf but it is returning (GdkPixbuf::Pixbuf | Nil) #103

Open phil294 opened 2 years ago

phil294 commented 2 years ago
# converting your_bytes into a pixbuf
stream = Gio::MemoryInputStream.new_from_bytes(GLib::Bytes.new(your_bytes))
pixbuf = GdkPixbuf::Pixbuf.new_from_stream(stream, nil)

fails with

 65119 | def self.new_from_stream(stream : Gio::InputStream, cancellable : Gio::Cancellable?) : self
                                                                                                ^
Error: method GdkPixbuf::Pixbuf.new_from_stream must return GdkPixbuf::Pixbuf but it is returning (GdkPixbuf::Pixbuf | Nil)

And here is the relevant snippet from the generated GdkPixbuf::Pixbuf:

def self.new_from_stream(stream : Gio::InputStream, cancellable : Gio::Cancellable?) : self
      __var0 = Pointer(LibGLib::Error).null
      __var1 = LibGdkPixbuf.pixbuf_new_from_stream(stream.to_unsafe_inputstream, cancellable ? cancellable.to_unsafe_cancellable : Pointer(LibGio::Cancellable).null, pointerof(__var0))
      GLib::Error.assert(__var0)
      __var2 = cast(GdkPixbuf::Pixbuf.new(__var1)) if __var1
      __var2
    end

This __var2 = something optional; return __var2 (this must always be failing (?)) with function return type self occurs several times in other functions too.


On an unrelated note, I want to mention that I have now been using crystal-gobject not only for Gtk but also for Atspi 2.0 bindings recently and it has been a bliss! Combined with the C docs it gives you everything you could ask for.