import with renaming and public import inside module

anonymous via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Apr 29 04:10:05 PDT 2014


On Tuesday, 29 April 2014 at 09:57:08 UTC, ketmar wrote:
> On Monday, 28 April 2014 at 15:57:16 UTC, anonymous wrote:
>> `zmod.symbol` works, too.
> no, it's not. at least on latest GDC.

Works for me with Ubuntu's gdc 4.8.2-1ubuntu6. My little test 
case:

my/module_.d:
---
module my.module_;
public import other.module_;
---

other/module_.d:
---
module other.module_;
int symbol;
---

mainprogram.d:
---
module mainprogram;
import zmod = my.module_;
static assert(is(typeof(zmod.symbol) == int)); /* passes */
---

>> I don't think so. The point of the renamed import is that you 
>> have to use the new name.
> but i renamed only my.module, not others. nothing hints me that 
> renaming is SO global. it's counterintuitive.

Checking the documentation, it's a little unclear. You might be 
right in your expectations:

"An import can be specifically declared public, when it will be 
treated as if any imports of the module with the 
ImportDeclaration [here: my.module_] also import the public 
imported modules [other.module_]."[1]

That doesn't mention renamed imports, though. Are those generated 
imports supposed to be renamed, too? If so (apparently current 
behaviour), you'd have to write `zmod.symbol`. If not (what you 
expected), just `symbol` should work.

Personally, I think the current behaviour is fine. Renamed 
imports are supposed to guard you against name clashes. If public 
imports wouldn't get renamed, too, that guard would be 
circumvented.


[1] http://dlang.org/module.html#ImportDeclaration


More information about the Digitalmars-d-learn mailing list