Index: attrib.c
===================================================================
--- attrib.c	(revision 196)
+++ attrib.c	(working copy)
@@ -562,6 +562,29 @@
     }
 }
 
+void ProtDeclaration::importAll(Scope *sc)
+{
+    Scope *newsc = sc;
+    if (sc->protection != protection ||
+	sc->explicitProtection != 1)
+    {
+	// create new one for changes
+	newsc = new Scope(*sc);
+	newsc->flags &= ~SCOPEfree;
+	newsc->protection = protection;
+	newsc->explicitProtection = 1;
+    }
+
+    for (int i = 0; i < decl->dim; i++)
+    {
+	Dsymbol *s = (Dsymbol *)decl->data[i];
+	s->importAll(newsc);
+    }
+
+    if (newsc != sc)
+	newsc->pop();
+}
+
 void ProtDeclaration::semantic(Scope *sc)
 {
     if (decl)
@@ -1143,7 +1166,38 @@
     return condition->include(sc, sd) ? decl : elsedecl;
 }
 
+void ConditionalDeclaration::setScope(Scope *sc)
+{
+    Array *d = include(sc, NULL);
 
+    //printf("\tAttribDeclaration::setScope '%s', d = %p\n",toChars(), d);
+    if (d)
+    {
+	for (unsigned i = 0; i < d->dim; i++)
+	{
+	    Dsymbol *s = (Dsymbol *)d->data[i];
+
+	    s->setScope(sc);
+	}
+    }
+}
+
+void ConditionalDeclaration::importAll(Scope *sc)
+{
+    Array *d = include(sc, NULL);
+
+    //printf("\tAttribDeclaration::importAll '%s', d = %p\n",toChars(), d);
+    if (d)
+    {
+	for (unsigned i = 0; i < d->dim; i++)
+	{
+	    Dsymbol *s = (Dsymbol *)d->data[i];
+
+	    s->importAll(sc);
+	}
+    }
+}
+
 void ConditionalDeclaration::addComment(unsigned char *comment)
 {
     /* Because addComment is called by the parser, if we called
@@ -1262,7 +1316,16 @@
     return m;
 }
 
+void StaticIfDeclaration::importAll(Scope *sc)
+{
+    // do not evaluate condition before semantic pass
+}
 
+void StaticIfDeclaration::setScope(Scope *sc)
+{
+    // do not evaluate condition before semantic pass
+}
+
 void StaticIfDeclaration::semantic(Scope *sc)
 {
     Array *d = include(sc, sd);
Index: attrib.h
===================================================================
--- attrib.h	(revision 196)
+++ attrib.h	(working copy)
@@ -93,6 +93,7 @@
     ProtDeclaration(enum PROT p, Array *decl);
     Dsymbol *syntaxCopy(Dsymbol *s);
     void setScope(Scope *sc);
+    void importAll(Scope *sc);
     void semantic(Scope *sc);
     void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
 
@@ -148,6 +149,8 @@
     Array *include(Scope *sc, ScopeDsymbol *s);
     void addComment(unsigned char *comment);
     void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
+    void importAll(Scope *sc);
+    void setScope(Scope *sc);
 };
 
 struct StaticIfDeclaration : ConditionalDeclaration
@@ -159,6 +162,8 @@
     Dsymbol *syntaxCopy(Dsymbol *s);
     int addMember(Scope *sc, ScopeDsymbol *s, int memnum);
     void semantic(Scope *sc);
+    void setScope(Scope *sc);
+    void importAll(Scope *sc);
     const char *kind();
 };
 
Index: dsymbol.c
===================================================================
--- dsymbol.c	(revision 196)
+++ dsymbol.c	(working copy)
@@ -276,6 +276,10 @@
     scope = sc;
 }
 
+void Dsymbol::importAll(Scope *sc)
+{
+}
+
 /*************************************
  * Does semantic analysis on the public face of declarations.
  */
Index: dsymbol.h
===================================================================
--- dsymbol.h	(revision 196)
+++ dsymbol.h	(working copy)
@@ -129,6 +129,7 @@
     virtual Dsymbol *toAlias();			// resolve real symbol
     virtual int addMember(Scope *sc, ScopeDsymbol *s, int memnum);
     virtual void setScope(Scope *sc);
+    virtual void importAll(Scope *sc);
     virtual void semantic(Scope *sc);
     virtual void semantic2(Scope *sc);
     virtual void semantic3(Scope *sc);
Index: import.c
===================================================================
--- import.c	(revision 196)
+++ import.c	(working copy)
@@ -79,7 +79,7 @@
     return si;
 }
 
-void Import::load(Scope *sc)
+int Import::load(Scope *sc)
 {
     DsymbolTable *dst;
     Dsymbol *s;
@@ -102,6 +102,7 @@
 #endif
     }
 
+    int justloaded = 0;
     if (!mod)
     {
 	// Load module
@@ -110,11 +111,13 @@
 					// if so then insert alias
 	if (!mod->importedFrom)
 	    mod->importedFrom = sc ? sc->module->importedFrom : Module::rootModule;
+	justloaded = 1;
     }
     if (!pkg)
 	pkg = mod;
 
     //printf("-Import::load('%s'), pkg = %p\n", toChars(), pkg);
+    return justloaded;
 }
 
 void escapePath(OutBuffer *buf, const char *fname)
@@ -137,12 +140,32 @@
     }
 }
 
+void Import::importAll(Scope *sc)
+{
+    if(!mod)
+    {
+	if(load(sc))
+	    mod->importAll(0);
+
+	if (!isstatic && !aliasId && !names.dim)
+	{
+	    /* Default to private importing
+	     */
+	    enum PROT prot = sc->protection;
+	    if (!sc->explicitProtection)
+		prot = PROTprivate;
+	    sc->scopesym->importScope(mod, prot);
+	}
+    }
+}
+
 void Import::semantic(Scope *sc)
 {
     //printf("Import::semantic('%s')\n", toChars());
+    if(!mod)
+	if(load(sc))
+	    mod->importAll(0);
 
-    load(sc);
-
     if (mod)
     {
 #if 0
Index: import.h
===================================================================
--- import.h	(revision 196)
+++ import.h	(working copy)
@@ -50,7 +50,8 @@
 
     const char *kind();
     Dsymbol *syntaxCopy(Dsymbol *s);	// copy only syntax trees
-    void load(Scope *sc);
+    int load(Scope *sc);
+    void importAll(Scope *sc);
     void semantic(Scope *sc);
     void semantic2(Scope *sc);
     Dsymbol *toAlias();
Index: mars.c
===================================================================
--- mars.c	(revision 196)
+++ mars.c	(working copy)
@@ -1046,6 +1046,17 @@
 	fatal();
 #endif
 
+    // load all unconditional imports for better symbol resolving
+    for (i = 0; i < modules.dim; i++)
+    {
+	m = (Module *)modules.data[i];
+	if (global.params.verbose)
+	    printf("import  %s\n", m->toChars());
+	m->importAll(0);
+    }
+    if (global.errors)
+	fatal();
+
     // Do semantic analysis
     for (i = 0; i < modules.dim; i++)
     {
Index: module.c
===================================================================
--- module.c	(revision 196)
+++ module.c	(working copy)
@@ -626,46 +626,79 @@
     }
 }
 
-void Module::semantic()
-{   int i;
-
-    if (semanticstarted)
-	return;
-
-    //printf("+Module::semantic(this = %p, '%s'): parent = %p\n", this, toChars(), parent);
-    semanticstarted = 1;
-
+void Module::importAll(Scope* prevsc)
+{
     // Note that modules get their own scope, from scratch.
     // This is so regardless of where in the syntax a module
     // gets imported, it is unaffected by context.
-    Scope *sc = Scope::createGlobal(this);	// create root scope
+    Scope* sc = Scope::createGlobal(this);	// create root scope
 
-    //printf("Module = %p, linkage = %d\n", sc->scopesym, sc->linkage);
-
     // Add import of "object" if this module isn't "object"
     if (ident != Id::object)
     {
-	Import *im = new Import(0, NULL, Id::object, NULL, 0);
-	members->shift(im);
+	if(members->dim == 0 || ((Dsymbol *)members->data[0])->ident != Id::object)
+	{
+	    Import *im = new Import(0, NULL, Id::object, NULL, 0);
+	    members->shift(im);
+	}
     }
 
-    // Add all symbols into module's symbol table
-    symtab = new DsymbolTable();
-    for (i = 0; i < members->dim; i++)
-    {	Dsymbol *s = (Dsymbol *)members->data[i];
-	s->addMember(NULL, sc->scopesym, 1);
+    int i;
+
+    if(!symtab)
+    {
+	// Add all symbols into module's symbol table
+	symtab = new DsymbolTable();
+	for (i = 0; i < members->dim; i++)
+	{
+	    Dsymbol *s = (Dsymbol *)members->data[i];
+	    s->addMember(NULL, sc->scopesym, 1);
+	}
     }
+    // anything else should be run after addMember, so version/debug symbols are defined
 
     /* Set scope for the symbols so that if we forward reference
      * a symbol, it can possibly be resolved on the spot.
      * If this works out well, it can be extended to all modules
      * before any semantic() on any of them.
      */
+    setScope(sc); // remember module scope for semantic
     for (i = 0; i < members->dim; i++)
     {	Dsymbol *s = (Dsymbol *)members->data[i];
 	s->setScope(sc);
     }
 
+    for (i = 0; i < members->dim; i++)
+    {
+	Dsymbol *s = (Dsymbol *)members->data[i];
+	s->importAll(sc);
+    }
+
+    if(sc != prevsc)
+    {
+	sc = sc->pop();
+	sc->pop();		// 2 pops because Scope::createGlobal() created 2
+    }
+}
+
+void Module::semantic()
+{   int i;
+
+    if (semanticstarted)
+	return;
+
+    //printf("+Module::semantic(this = %p, '%s'): parent = %p\n", this, toChars(), parent);
+    semanticstarted = 1;
+
+    // Note that modules get their own scope, from scratch.
+    // This is so regardless of where in the syntax a module
+    // gets imported, it is unaffected by context.
+    Scope *sc = scope;
+    if (!sc)
+	sc = Scope::createGlobal(this);	// create root scope
+
+    //printf("Module = %p, linkage = %d\n", sc->scopesym, sc->linkage);
+
     // Pass 1 semantic routines: do public side of the definition
     for (i = 0; i < members->dim; i++)
     {	Dsymbol *s = (Dsymbol *)members->data[i];
@@ -675,8 +708,11 @@
 	runDeferredSemantic();
     }
 
-    sc = sc->pop();
-    sc->pop();		// 2 pops because Scope::createGlobal() created 2
+    if (!scope)
+    {
+        sc = sc->pop();
+	sc->pop();		// 2 pops because Scope::createGlobal() created 2
+    }
     semanticRun = semanticstarted;
     //printf("-Module::semantic(this = %p, '%s'): parent = %p\n", this, toChars(), parent);
 }
Index: module.h
===================================================================
--- module.h	(revision 196)
+++ module.h	(working copy)
@@ -122,6 +122,7 @@
 #else
     void parse();	// syntactic parse
 #endif
+    void importAll(Scope *sc);
     void semantic();	// semantic analysis
     void semantic2();	// pass 2 semantic analysis
     void semantic3();	// pass 3 semantic analysis
