[fpc-pascal] private type and type compatibility
Sven Barth
pascaldragon at googlemail.com
Wed Oct 30 12:11:12 CET 2013
Am 30.10.2013 12:06, schrieb Frederic Da Vitoria:
> 2013/10/30 Jonas Maebe <jonas.maebe at elis.ugent.be
> <mailto:jonas.maebe at elis.ugent.be>>
>
> On 30 Oct 2013, at 10:36, Michael Van Canneyt wrote:
>
> I think it is an error. You declare something as private, and
> then you use it in a public function ? If that is not a
> visibility clash, I don't know what is :)
>
>
> The ability to use types in public functions that are not
> necessarily visible to users of that function is quite common in
> Pascal. Otherwise, for consistency you would also have to give a
> compile time error when compiling this:
>
> unit u1;
>
> interface
>
> type
> tdynarray = array of integer;
>
> implementation
>
> end.
> *********
>
> unit u2;
>
> interface
>
> uses
> u1;
>
> function f: tdynarray;
>
> implementation
>
> function f: tdynarray;
> begin
> end;
>
> end.
> **********
>
> program test;
>
> uses
> u2;
>
> var
> a: array of integer;
> begin
> a:=f;
> end.
> ***
>
> The tdynarray type is not visible in the program because u1 is not
> in its uses clause (it's not in scope whatsoever), and
> nevertheless there is no problem to use it. It's of course not
> exactly the same (tdynarray isn't declared as private to u1), but
> at the scope visibility level it is the same situation as far as I
> am concerned.
>
>
> Precisely, shouldn't this trigger an error too? The code should not be
> able to reference anything for which the declaration isn't visible,
> isn't it?
But the compiler can not know whether the user of unit u2 has unit u1 in
scope or not.
Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20131030/759d337b/attachment.html>
More information about the fpc-pascal
mailing list