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 725356 - request: add safe navigation operator
request: add safe navigation operator
Status: RESOLVED DUPLICATE of bug 761267
Product: vala
Classification: Core
Component: general
0.22.x
Other Linux
: Normal enhancement
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2014-02-27 22:51 UTC by Travis Reitter
Modified: 2018-02-24 11:39 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Travis Reitter 2014-02-27 22:51:33 UTC
It seems like it would be useful to add a safe navigation operator so accessing children of children on an object can be done conveniently without having to check for nullity until the end.

Eg, this would be safe regardless of the nullity of any of the members on the right side:

var foo = parent?.child1?.child2;
if (foo != null) {
// continue
}

This saves a lot of noisy code in cases where you only care if you can access the endpoint member.

C# is adding this as "?.". More explanation here:

http://blogs.msdn.com/b/jerrynixon/archive/2014/02/26/at-last-c-is-getting-sometimes-called-the-safe-navigation-operator.aspx
Comment 1 Luca Bruno 2014-02-27 22:58:10 UTC
There was a discussion already about this on the vala mailing list, can't find the relevant bits though.
Comment 2 Michael 'Mickey' Lauer 2018-02-24 11:39:47 UTC

*** This bug has been marked as a duplicate of bug 761267 ***