Passing of `out Foo? f` parameters become semi-null..?
Vala 0.56.1.162-94582
Consider the following code, the code does not produce an executable that behaves as expected.
// valac --profile=posix main.vala
using Posix;
public enum MyErrorType {
INVALID = 0,
OUT_OF_RANGE,
OTHER,
__END;
}
public struct MyError {
public string message;
public MyErrorType type;
public MyError (MyErrorType t, string msg) {
this.type = t;
this.message = msg;
}
public MyError.OUT_OF_RANGE (string message) {
MyError (MyErrorType.OUT_OF_RANGE, message);
}
}
void foo (int a, out MyError? ex) {
if ((a >= 5) || (0 >= a)) {
ex = MyError.OUT_OF_RANGE (@"Out of range: Value $a is out of range (0 - 5).");
} else {
ex = null;
}
if (ex == null)
stdout.printf ("AAAAA\n");
else
stdout.printf (@"BBBBB: $(ex.message)\n");
}
int main (string[] args) {
MyError? ex;
foo (1, out ex);
if (ex != null) {
stderr.printf ("Error1: %s\n", ex.message);
}
foo (10, out ex);
if (ex != null) {
stderr.printf ("Error2: %s\n", ex.message);
}
return 0;
}
The expected output should be as follows:
$ ./main
AAAA
BBBB: Out of range: Value 10 is out of range (0 - 5).
Error2: Out of range: Value 10 is out of range (0 - 5).
instead we get:
$ ./main
AAAAA
Error2: (null)
If i follow the execution, the memory from __tmp5__
is seems to be copied correctly and returned to the main execution, and the logic in main seems to be correct. I am genuinely confused by this one, and it smells like a code emission bug, but I can't figure out what is wrong.