Import proposals (Discuss)

Derek Parnell derek at nomail.afraid.org
Tue Jul 11 17:10:39 PDT 2006


On Wed, 12 Jul 2006 02:37:00 +0300, Jari-Matti Mäkelä wrote:

> Tyro wrote:
>> Just in case that doesn't make any sense, let me try it a another way: By
>> importing [a.d] into [b.d] and by virtue of std.stdio being publicly imported
>> into [a.d], you have also imported std.stdio into [b.d]. If imports are made
>> private by default or if explicitly imported privately, then an error message
>> similar to the one suggested earlier is expected.
> Exactly.
> 
> As a side note: I just installed dmd 0.162 and it seems imports have
> been finally fixed. Now private imports and private members really are
> private, yay! This means that private members are not accessible, but
> they are visible to the unprivileged modules. Private imports are not
> visible nor accessible. Yes, this is how it really should work. Even
> diamond shaped import constructions work according to my simple test
> suite. Simply excellent! Thank you Walter!

Almost anyway... 
(1) FQN usage incorrectly overrides 'private'.

Consider these five files ...

 // ---- aaa.d -----
 private int foo() { return 1; }

 // ---- bbb.d ----
 private import aaa;
 private int bar() { return 2; }

 // ---- ccc.d ----
 private int foo() { return 3; }

 // ---- ddd.d ----
 private import ccc;
 private int bar() { return 4; }

 // ---- eee.d ----
 import bbb;
 import ddd;
 import std.stdio;
 void main()
 {
    writefln("aaa.foo %s", aaa.foo());
    writefln("bbb.bar %s", bbb.bar());
    writefln("ccc.foo %s", ccc.foo());
    writefln("ddd.bar %s", ddd.bar());
 }

This compiles fine and when run I get ...

 aaa.foo 1
 bbb.bar 2
 ccc.foo 3
 ddd.bar 4

(2) The error message given when not using FQN is not very helpful.

Change the eee.d file to ...
 // ---- eee.d ----
 import bbb;
 import ddd;
 import std.stdio;
 void main()
 {
    writefln("bar %s", bar());
 }

And the compiler gives this message ...

 bbb.d(3): function bbb.bar conflicts with ddd.bar at ddd.d(3)
 eee.d: module eee bbb.bar is private

The problems with this message are that it doesn't give the line number in
eee.d that triggered the message, and that it exposes 'private' stuff to
the coder. A better message might be along the lines of ...

 eee.d(6): No accessible function 'bar' was found.

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocrity!"
12/07/2006 10:02:30 AM



More information about the Digitalmars-d mailing list