GNOME Bugzilla – Bug 660049
First construction(g_object_new) might depend on if statement
Last modified: 2018-05-22 14:10:18 UTC
Created attachment 197422 [details] All in one(user_config.vala, user_config.c.before, user_config.c.after) When a construct method is written in Vala, Vala won't always call directly to g_object_new () . This is when another construction method is called, and before changing any fields. Now what would happen if the construction call is inside "if"? Take a look at this code: internal UserConfig.from_path (string conf_path, UserConfig? default_conf = null) { //Cloning default if passed // Posible fix, but it's failed(self is null) //_use_player_select_popup = false; if (default_conf == null) // Another posible fix, but it's failed(multiply constructors - even when inside if) //this ();// (Please assume it's exist) report_trace ("It's so null!"); else { report_trace ("It's not null!"); this.from_another (default_conf);// This is a clone constructor } ... } You can see the problem in the c files when compiling it. I compile it for you(as attachment) in valac 0.12, user_config.c.before(this code) and user_config.c.after(when commenting "this.from_another (default_conf);"). As you can see, I thought about two possible fixes, but doesn't help. Note that those are also shell considered as bug: In the first possible fix, a field is being set before construction call, but it's should be valid because construction is depended on if statement. In the second possible fix, it also fails because of multiply constructors error, even when each one is in another if block. It shouldn't be error. 3 bugs eventually. The only fix without changing valac, is not to use constructors, but static methods. I hope you won't choose these last exit, because it's possible to do it in C. Thanks, Tal
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/vala/issues/234.