Waldek Hebisch wrote:
Frank Heckenbach wrote:
- 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?
Only if `o' is not shadowed -- in your example it is shadowed, so inside `oo' parent is not accesible. The same problem appears if you use `with' (and have just three records, one outside, a big one and a small one inside big shadowing the one outside).
By the way, I agree that systax is correct -- intentionaly method call, filed acess and qualified acess share the same syntax, but to have valid method call you need an object -- `o' needs to denote an object at the place of call. Besides your example the following should be valid:
procedure oo.foo; var o : integer; begin for o:=0 to 1 do something; end;
And inside `oo.foo' an attempt to acces `o.f' is invalid.
- 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?
The same as 1 -- yes unless shadowed.
Do you agree that the preconditions of both 1. and 2. are fulfilled in my original program?
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.
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.
I see that you do not like shadowing -- normal Pascal rules are that names in inner scope shadow names in outsde scope. And object do introduce a new scope. Shadowing may be confusing, but it happens and scope rules are supposed to minimize confusion.
I'm not sure this is like normal shadowing because both meanings of `o.f' come "into scope" at the same point, i.e. on method entry.
I think it's similar to conflicts between object field or method names with method parameter names or even method local variable names, which both GPC and BP do not allow, although syntactically they could been seen as in different scopes. Apparently there's some consensus that this is not shadowing (because they also both come into scope on method entry).
OK, it might be a gray area. I think we agree that it's at least potentially dangerous, so a warning seems in order. The question is where it will be an error. Not in BP mode, for compatibility, sure. In (future) OOE mode it must be an error. In default mode, we have the choice. I don't see quite the difference to the latter example, but if you really want only a warning by default, ok.
Frank