Prof A Olowofoyeku (The African Chief) wrote:
On 18 May 2004 at 22:06, Frank Heckenbach wrote:
Prof A Olowofoyeku (The African Chief) wrote:
On 18 May 2004 at 4:03, Frank Heckenbach wrote:
I just found another problem in BP's OOP. In the following program, `o.f' in oo.p is ambiguous. It could mean field f of the field o, or function f of the parent type o. Both BP and GPC (currently) do the former (i.e., say 99).
I noticed this because the OOE draft forbids this case by requiring that object fields don't clash with parent type names.
We do we do here? Allow it in BP mode with a warning, error otherwise?
program Foo;
type o = object function f: Integer; end;
oo = object (o) o: record f: Integer end; procedure p; end;
function o.f: Integer; begin f := 42 end;
procedure oo.p; begin WriteLn (o.f) end;
var v: oo;
begin v.o.f := 99; v.p end.
This looks okay to me (i.e., I would expect "99"). The "Writeln (o.f)" clearly refers to the "f" field of the record "o". The fact that it is qualified makes it clear (to me at least). It could not possible refer to the function "f" in the parent object, because using the base name of the parent object in this manner must generate a compiler error.
Not at all. If we rename the field, both GPC and BP call the parent method and say 42. This shows that the parent method call is syntactically correct (and I see no reason why it shouldn't -- it's the normal form of parent method calls).
[...]
I am not sure that I made myself clear. This variation of the program shows what I meant.
program Foo;
type o = object function f: Integer; end;
oo = object (o) o: record af: Integer { we have renamed this field } end; procedure p; end;
function o.f: Integer; begin f := 42 end;
procedure oo.p; begin WriteLn (o.af); WriteLn (o.f); { this must and does generate a compiler error } end;
var v: oo;
begin v.o.af := 99; v.p end.
As you can see, the point that I made is correct. The original program was not ambiguous, and "Writeln (o.f)" in the original "procedure oo.p" could only correctly refer to the "f" field of the "o" record - it could not correctly refer to the "f" method (unless I am missing something).
Perhaps I was unclear -- I meant renaming the object field `o', not the record field `f'. Then you wil see that `o.f' is valid syntax for a parent method call.
You can probably also look up the syntax in the Borland manuals. As I said, that's the normal syntax for a parent method call, and AFAIK the only one besides `inherited f'.
Frank