Search code examples
valaubuntu-16.04

Cannot convert from `GLib.TypeClass' to `GLib.ObjectClass'


I was trying to compile libfriends (source) against valac (.28) and libgee (1.0). I specifically compiled these against Ubuntu-16.04 stack.

But I am getting following error

entry.vala:397.38-397.38: warning: if-statement without body if (_selected != value); ^ entry.vala:172.52-172.86: error: Argument 1: Cannot convert from `GLib.TypeClass' to `GLib.ObjectClass' binding_set = Gtk.BindingSet.by_class (typeof (InputTextView).class_ref ());

I don't really find anything wrong with code. Any Idea?

The entire buildlog is here: https://launchpadlibrarian.net/263631082/buildlog_ubuntu-xenial-i386.libfriends_0.1.2+14.10.20140709+201606051415~ubuntu16.04.1_BUILDING.txt.gz


Solution

  • I just checked and it compiles with valac-0.18, but doesn't compile with valac-0.28.

    So there must have been a change between those valac versions that does more strict type checking in this case.

    GLib.TypeClass (really GTypeClass in C) is the parent class of GLib.ObjectClass (really GObjectClass in C).

    So the compiler is correct to not allow this without a cast. I don't know if the cast is correct in this situation, but it makes the code compile:

    binding_set = Gtk.BindingSet.by_class ((ObjectClass) typeof (InputTextView).class_ref ())
    

    See also valadoc for GObjectClass where a similar typecast is done in the example code:

    http://valadoc.org/#!api=gobject-2.0/GLib.ObjectClass