The following code gives a stack overflow:
function Func(x : Double) : Double; overload;
function Func(x : Integer) : Double; overload;
function Func(x : Double) : Double;
begin
Result := Func(Round(x));
end;
function Func(x : Integer) : Double;
begin
Result := 1.0;
end;
The Integer
overloaded function is never called, the Double
overloaded function calls itself until the stack overflows.
The following code works as expected:
function Func2(x : Double) : Double; overload;
function Func2(x : Integer) : Double; overload;
function Func2(x : Double) : Double;
var
ix : Integer;
begin
ix := Round(x);
Result := Func(ix);
end;
function Func2(x : Integer) : Double;
begin
Result := 1.0;
end;
Is this a compiler bug or expected behavior?