While assisting in porting MacPascal Object Pascal code to GPC, I
encountered a bug in GPC's scope rules implementation for object field
and method formal parameter identifiers. The same bug also exists with
the OOE objects implementation. The follow examples (one for
mac-objects and one for ooe-objects) along with the respective GPC
compilation error demonstrate the bug:
{$ooe-objects}
program ClassScopeBug(output);
type
Tclass = class
x: integer;
procedure y(x: real); { Should be legal}
end;
procedure Tclass.y(x: real);
begin
end;
begin
writeln('OK');
end.
ClassScopeBug.pas:8: error: formal parameter `x' of method `y' conflicts
with field or method
{$mac-objects}
program ObjectScopeBug(output);
type
Tobj = object
x: integer;
procedure y(x: real); { Should be legal}
end;
procedure Tobj.y(x: real);
begin
end;
begin
writeln('OK');
end.
ObjectScopeBug.pas:8: error: formal parameter `x' of method `y'
conflicts with field or method
Both the MacPascal Object Pascal object and the Object-Oriented
Extensions for Pascal class have the same 6.2.2 Scopes requirements
extensions in this area. Although stated informally; implied through
syntax extensions; and informal behavioral descriptions, the
formal-parameter-list of a method heading is a separate scope region for
which 6.2.2.5 scope exclusion requirements apply. The "Object-Oriented
Extensions for Pascal" Technical Report in paragraph 6.5.4 "Implicit
References" also states in part:
"...Therefore, a parameter identifier or a local variable with the same
spelling as a name brought in will hide the name brought in. A name so
hidden can be accessed by explicit use of the class name and qualification."
Therefore, there is no conflict between formal parameter `x' of method
`y' and object/class field `x' since object/class field `x' is excluded
from the scope of method `y' 's formal-parameter-list and method body.
Since there is no violation of either object models' requirements, GPC
should compile both of the example programs without any errors.
The GPC I'm using is built from Adriaan's Mac OX X GPC sources
distribution which I've upgraded to use Waldek's gpc-20060325 snapshot
GPC sources. The specs are:
Reading specs from /Developer/Pascal/gpc345u2d1/lib/gcc/powerpc-apple-darwin8/3.4.5/specs
Configured with: ../gcc-3.4.5/configure --enable-languages=pascal,c
--enable-threads=posix --target=powerpc-apple-darwin8
--host=powerpc-apple-darwin8 --build=powerpc-apple-darwin8 --prefix=/Developer/Pascal/gpc345u2d1
Thread model: posix
gpc version 20060325, based on gcc-3.4.5
Gale Paeper
gpaeper(a)empirenet.com