GNOME Bugzilla – Bug 534756
Can't compile code with Time class as property
Last modified: 2008-12-17 23:51:41 UTC
See topic. Compiling gives: $ valac -o testtime testtime.vala testtime.c: In function 'timer_new': testtime.c:31: error: incompatible type for argument 2 of 'g_value_set_pointer' error: cc exited with status 256
Created attachment 111497 [details] Test case
Is this just a namespace collision? http://library.gnome.org/devel/glib/stable/glib-Timers.html public class Test.Timer : GLib.Object { public Time TimeTM; public void run (int year, int month, int day, int hour, int minute) { this.TimeTM = this.create_time (year, month, day, hour, minute); } // Etc ... Works fine for me with valac 0.3.2.
I'm using valac 0.3.2, too, on Ubuntu hardy, and it doesn't work for me. I used "class Test.Timer" put the class in a namespace, didn't import GLib and used GLib.Time. The error is always present.
Created attachment 111563 [details] Fixed constructor issue Hi, Think I see the problem. In Vala, named public constructor can only set values. It can't call methods, only the special construct {} method can do that. See attached file for working example, it caught me out a couple of times too ;)
It's obviously a hack, because I have to keep year, month, day, etc. around to use it again in construct. That way I wouldn't need the Time property anymore, because I already have all the information I need. According to Jürg using this.create_method in the named constructor should be fine.
Been using run methods to sidestep the issue. I'm just going off observed behavior, obviously Jürg knows best. Should this one be closed and a new bug opened? using GLib; public class CreateMethod : Object { public int prop {get; construct;} CreateMethod (int p1, int p2) { this.prop = this.create_method (p1, p2); } public int create_method (int p1, int p2) { return p1 + p2; } public static void main () { var t = new CreateMethod (1, 1); message (t.prop.to_string ()); } } CRITICAL **: create_method_create_method: assertion `IS_CREATE_METHOD (self)' failed
self NULL at this point, making create_method static works. However, the problem with the Time property remains.
Also the original error you reported is still a bug, arg 2 of generated code should be a g_pointer: g_value_set_pointer (&__params_it->value, test_timer_create_time (self, year, month, day, hour, minute)); test_timer_create_time is generated as a struct, bug is not there in the test case I posted above because create_method is generated as a function and called with g_value_set_int.
Confirming, this should be fixed when we fix bug 534781
Created attachment 114416 [details] Another test case I justed tried it with r1696 and a Time property with get and set. Code compiles, but when I run the program I get: (process:28505): GLib-GObject-WARNING **: IA__g_object_notify: object class `Test' has no property named `StartTime' This is a new error that didn't appear earlier.
2008-09-29 Jürg Billeter <j@bitron.ch> * gobject/valaccodegenerator.vala: Don't use g_object_notify for non-GObject properties, fixes bug 548442 Fixed in r1815. 2008-10-10 Jürg Billeter <j@bitron.ch> * gobject/valaccodecreationmethodbinding.vala: * gobject/valaccodemethodbinding.vala: Lift restriction on statements in creation methods of GObjects in preparation to support more flexible construction scheme Fixed in r1825.