After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 660049 - First construction(g_object_new) might depend on if statement
First construction(g_object_new) might depend on if statement
Status: RESOLVED OBSOLETE
Product: vala
Classification: Core
Component: Code Generator: GObject
0.12.x
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2011-09-25 10:34 UTC by Tal
Modified: 2018-05-22 14:10 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
All in one(user_config.vala, user_config.c.before, user_config.c.after) (4.11 KB, application/x-bzip)
2011-09-25 10:34 UTC, Tal
Details

Description Tal 2011-09-25 10:34: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
Comment 1 GNOME Infrastructure Team 2018-05-22 14:10:18 UTC
-- 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.