[fpc-pascal] private type and type compatibility

Frederic Da Vitoria davitofrg at gmail.com
Wed Oct 30 12:06:53 CET 2013


2013/10/30 Jonas Maebe <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?

-- 
Frederic Da Vitoria
(davitof)

Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20131030/d3a36035/attachment.html>


More information about the fpc-pascal mailing list