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 764440 - Null Coalescing Operator "??" evaluates both of expression when right side throws Error.
Null Coalescing Operator "??" evaluates both of expression when right side th...
Status: RESOLVED OBSOLETE
Product: vala
Classification: Core
Component: Code Generator
unspecified
Other All
: Normal minor
: ---
Assigned To: Jamie McCracken
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2016-04-01 03:19 UTC by Lim Jongrok
Modified: 2018-05-22 15:33 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add test-case for bug 764440 (1.21 KB, patch)
2016-11-08 14:03 UTC, Rico Tzschichholz
none Details | Review

Description Lim Jongrok 2016-04-01 03:19:29 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.
Comment 1 Rico Tzschichholz 2016-11-08 14:03:18 UTC
Created attachment 339317 [details] [review]
Add test-case for bug 764440
Comment 2 Michael 'Mickey' Lauer 2018-02-26 09:30:52 UTC
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?
Comment 3 GNOME Infrastructure Team 2018-05-22 15:33:30 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/534.