Null Coalescing Operator "??" evaluates both of expression when right side throws Error.
Submitted by Lim Jongrok
Link to original bug (#764440)
Description
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.
To upload designs, you'll need to enable LFS and have admin enable hashed storage. More information