Local variable initialization check fails on if statements
Submitted by Andrea Del Signore
Please describe the problem:
Vala reports the use of unitialized local variable if the initialization is enclosed in an expression inside an if statement
public class Bugs.Test
{
public bool set_out_param (out int param)
{
param = 1;
return true;
}
public bool dummy_test ()
{
return true;
}
public static void main ()
{
var t = new Bugs.Test ();
int i;
t.set_out_param (out i);
stdout.printf ("i is %d", i);
int j;
if (t.dummy_test () && t.set_out_param (out j)) {
stdout.printf ("j is %d", j);
}
}
}
Actual results:
valac /home/andrea/Desktop/outbug.vala
outbug.vala:26.4-26.32: error: use of possibly unassigned local variable `j'
stdout.printf ("j is %d", j);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Compilation failed: 1 error(s), 0 warning(s)
Expected results:
no error
Does this happen every time?
yes
Other information:
I think that the problem is related to the and (&&
) expression since without it the example compiles fine
Version: 0.35.x
Edited by Rico Tzschichholz