www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - import inside a class overrides symbols imported in module scope?

reply Trass3r <un known.com> writes:
It was quite hard to track that one down.
In the following example the import statement was mixed into the class  
among other code so it wasn't as obvious as here.

import std.traits;
class Foo
{
	import std.string;
	static assert(isNumeric!int);
}


foo.d(6): Error: template instance isNumeric is not a template  
declaration, it is a function
foo.d(6): Error: static assert  (isNumeric!(int)) is not evaluatable at  
compile time

(There's an isNumeric function in std.string)


Local variables override global ones, but is this correct as well?
Dec 09 2010
parent =?UTF-8?B?UGVsbGUgTcOlbnNzb24=?= <pelle.mansson gmail.com> writes:
On 12/09/2010 10:53 PM, Trass3r wrote:
 It was quite hard to track that one down.
 In the following example the import statement was mixed into the class
 among other code so it wasn't as obvious as here.

 import std.traits;
 class Foo
 {
 import std.string;
 static assert(isNumeric!int);
 }


 foo.d(6): Error: template instance isNumeric is not a template
 declaration, it is a function
 foo.d(6): Error: static assert (isNumeric!(int)) is not evaluatable at
 compile time

 (There's an isNumeric function in std.string)


 Local variables override global ones, but is this correct as well?

You probably want to use static import when mixing stuff in, to avoid this accidental invasion of namespace.
Dec 09 2010