Hi
I just switched to 4.1.3 from 4.0.5 and suddenly some new warnings pop up. They are all related to using local functions.
Some example code (not useful, but for demonstration…)
function foo()
{
var loops = 0;
var someRecursiveFunction:Int->Void;
var start:Void->Void;
someRecursiveFunction = function(value:Int)
{
if (value < 10)
someRecursiveFunction(++value);
else if (++loops < 5)
start();
}
start = function()
{
var value = Std.int(Math.random() * 5);
trace("staring with value", value);
someRecursiveFunction(value);
}
start();
}
The compiler will throw two warnings. The two function calls in the recursive function.
First one is the call to the “someRecursiveFunction(++value)”. This makes no sense as this is just a recursive call.
Second one is the “start()” call two lines beneath. “start” will always be defined, because the only situation where “someRecursiveFunction” is called, is in the “start” function itself.
The only way that the compiler isn’t complaining is this:
function foo()
{
var loops = 0;
var start:Void->Void = null;
function someRecursiveFunction(value:Int)
{
if (value < 10)
someRecursiveFunction(++value);
else if (++loops < 5)
start();
}
start = function()
{
var value = Std.int(Math.random() * 5);
trace("staring with value", value);
someRecursiveFunction(value);
}
start();
}
But I really don’t like it. Two different styles of defining local functions and the “= null;” is somehow useless…
Thanks