kevingadd/JSIL — Issue #44: JSILC generates JS, that uses uninitialized variable if it is being passed by ref to another method 
Author: matra774
Created: 2011-12-04 22:05:58+00:00
State: open

Here is the minimal test case (reduced version of IEnumerable.ToArray from MOno implementation):

public class RefArrayTest
{
public void SomeRefFunction2(ref int[] x)
{
}
public int[] MyTest(bool dummy)
{
int[] array;
if (dummy) // if you remove this and the following 4 lines, then the generated code is OK
{
array = new int[3];
return array;
}
array = null;
SomeRefFunction2(ref array); //Array.Resize(ref array, pos * 2);
return array;
}

}

And here is the JS code generated:

JSIL.MakeClass(new JSIL.TypeRef($asm02, "System.Object"), "TestHelloWorld.RefArrayTest", true, [], function ($) {
$.prototype.SomeRefFunction2 = function (/* ref */ x) {
};
$.prototype.MyTest = function (dummy) {
if (dummy) {
var array = new JSIL.Variable(JSIL.Array.New($asm02.System.Int32, 3));
var result = array.value;
} else {
array.value = null; // **** UNINITIALIZED array, so array.value fails ****
this.SomeRefFunction2(/* ref */ array);
result = array.value;
}
return result;
};
$.prototype._ctor = function () {
$asm02.System.Object.prototype._ctor.call(this);
};

});