Effective D book?

Rainer Schuetze r.sagitario at gmx.de
Sun Jun 16 03:14:56 PDT 2013



On 15.06.2013 17:09, Peter Alexander wrote:
> On Saturday, 15 June 2013 at 12:20:46 UTC, Timon Gehr wrote:
>> One issue with local imports is that they hide local symbols.
>
> Can you give an example? I can't repro.
>

Here is another example I recently stumbled upon:

/////////
module a;

class A
{
	import std.stdio;
}

/////////
module b;

void writeln(string){}

class B : A
{
	void foo()
	{
		writeln("Hi");
	}
}

Guess which function is called in foo!

There are conflicting rule sets at work here, the symbol lookup rules 
for base classes vs the lookup rules for (private) imports.

Walter seems to be fine as is but I'm not sure 
(http://forum.dlang.org/post/5197E695.10807@digitalmars.com - the issue 
is not a regression as reported, there seems to be some change to it in 
2.063 that I couldn't isolate). At least the symbols imported into the 
base class should be private by default (though that won't change 
anything in the same module).

OT: This points to another slight non-orthogonality as declarations and 
imports have different visibility defaults, which is modified by the 
same "public:"/"private:".



More information about the Digitalmars-d mailing list