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.e., in the original program, both interpretations are valid (i.e., it's ambiguous), and one happens to take precendence (likely unintentionally -- I hadn't considered this case before, and I'm not sure Borland did).
On the other hand, "Writeln (f)" would refer to the function "f" in the parent object.
This refers to the method in the current object (which in this case is inherited from the parent). (You may be confusing inheritance with explicit parent method calls.) E.g., if you add a method f to the child, you have:
1. f: call of the child's method 2. o.f: call of the parent's method 3. o.f: access of the sub-field
(This may make the ambiguity clearer, but it's also there in the original program where 2. and 3. still apply, and 1. is equivalent to 2.)
Frank