Prof A Olowofoyeku (The African Chief) wrote:
On 19 May 2004 at 3:36, Frank Heckenbach wrote:
[...]
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'.
Of course. I think we are speaking at cross-purposes here. But the long and short of it is that I still do not see the ambiguity in the original example. Perhaps I am just too influenced by having used BP for far too long, and that is what is blinding me to the ambiguity.
I'm still not quite sure what your point is. So let's try it step by step:
1. Do you agree that if an object type `oo' has a parent type `o', and this parent has a method function `f', then in a method of `oo' the expression `o.f' is valid syntax for a call of that former method function?
2. Do you agree that if an object type has a field `o' which is a record which has a field `f' than within a method of this object type `o.f' is valid syntax to access this field?
3. Do you agree that the preconditions of both 1. and 2. are fulfilled in my original program?
4. If so, I suppose you'll agree that `o.f' in `oo.p' is valid syntax for both the parent method call and the subfield access. That's what an ambiguity is.
5. The fact that both BP and GPC so far choose one of the interpretations (namely 2.) does not mean that there is no ambiguity, just that it's resolved arbitrarily.
IAC, if one person sees something as ambiguous, then it is ambiguous, and so perhaps code like that should generate at least a warning (except in BP/Delphi mode). For my part, I would just leave it as it is.
Well, in fact, if it's ambiguous, the warning should be there even in BP mode (as we warn for other dangerous features), while elsewhere it may well be an error. (Since the declarations of the two `o's and `f's can be far apart in the program, it might not be easy for a programmer to notice such a problem if he ever runs into it, and he might be very confused by the field access if he's trying to call the parent method and unaware of the field name conflict. That's why I consider it a bit dangerous. BTW, I don't suppose Borland made it so intentionally -- perhaps they just overlooked this potential problem.)
BTW, I don't think many real programs would run into this problem, because object type names and field names are usually quite different. Therefore I'd almost like to forbid it entirely, but for compatibility's sake, I'll go with a warning in BP mode.
Frank