Am 30.10.2013 12:06, schrieb Frederic Da Vitoria:
2013/10/30 Jonas Maebe <jonas.ma...@elis.ugent.be <mailto:jonas.ma...@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
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to