GNOME Bugzilla – Bug 764440
Null Coalescing Operator "??" evaluates both of expression when right side throws Error.
Last modified: 2018-05-22 15:33:30 UTC
Null Coalescing Operator "??" evaluates both of left and right side of expression, when right side throws Error. This code: public errordomain SomeError { DUMMY_CODE } public class Something { private int value; public Something (int value = 0) { message ("Construction: %d", value); } public Something.throws_error (int value = 0) throws SomeError { this (value); } } public Something create_throwing (int value = 0) throws SomeError { return new Something (value); } public Something? create_nullable (int value = 0) { return new Something (value); } public void main () { try { Something? a = new Something (10); Something b = a ?? create_throwing (11); Something? c = new Something (101); Something? d = c ?? create_nullable (102); } catch (SomeError e) { assert_not_reached (); } } Results in: ** Message: something.vala:9: Construction: 10 ** Message: something.vala:9: Construction: 11 ** Message: something.vala:9: Construction: 101 which means, create_throwing (11) is evaluated even a is not null. create_nullable (102) isn't evaluated as c is not null.
Created attachment 339317 [details] [review] Add test-case for bug 764440
This looks like a sane change that is in line with the short circuit evaluation in many other languages. Any particular reason why this isn't committed yet?
-- 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/534.