Emil Jerabek wrote:
On Wed, Jan 29, 2003 at 02:03:57AM +0100, Frank Heckenbach wrote:
Consider the following situation:
program Foo;
function a: Integer;
function a: Integer; begin a := 42 end;
begin a := a end;
begin WriteLn ('OK') end.
The problem here is that within the outer `a', the identifier `a' can mean both its result variable and the local function `a'.
IMHO function heading does _not_ declare the function name as a real variable identifier.
Yes, it's a "functionÂidentifier" in terms of the standard.
It is allowed _only_ on the left-hand side of an assignment statement.
OK (6.9.2.2).
Anywhere else it behaves according to the usual Pascal scoping rules: in general this means a recursive call (because the name is defined in outer scope as a function identifier), but in the example above, it is shadowed by the local function declaration. (This is legal, because the scopes are different.)
But still the identifier `a' would refer to both functions (as a functionÂidentifier) on the left and right sides of the same statement?
EP's result value specifications (`function b = a: Integer') are different, they do declare a real variable. The following is not allowed, because identifier `a' is defined twice in the same scope:
function b = a: Integer;
function a: Integer; begin a := 42 end;
begin a := a end;
I agree here.
Frank