Skip to content

Commit

Permalink
fix Issue 7373 - (Regression git) Renamed imports conflict with other…
Browse files Browse the repository at this point in the history
… implicitly imported symbols
  • Loading branch information
WalterBright committed Jan 30, 2012
1 parent 3c13871 commit df5d8fa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
29 changes: 17 additions & 12 deletions src/import.c
Expand Up @@ -58,13 +58,11 @@ Dsymbol *Import::syntaxCopy(Dsymbol *s)
{
assert(!s);

Import *si;

si = new Import(loc, packages, id, aliasId, isstatic);
Import *si = new Import(loc, packages, id, aliasId, isstatic);

for (size_t i = 0; i < names.dim; i++)
{
si->addAlias(names.tdata()[i], aliases.tdata()[i]);
si->addAlias(names[i], aliases[i]);
}

return si;
Expand Down Expand Up @@ -187,6 +185,13 @@ void Import::semantic(Scope *sc)
{ //printf("module4 %s because of %s\n", sc->module->toChars(), mod->toChars());
sc->module->needmoduleinfo = 1;
}

if (aliasId)
{
AliasDeclaration *ad = new AliasDeclaration(loc, aliasId, mod);
sc->insert(ad);
ad->semantic(sc);

This comment has been minimized.

Copy link
@MartinNowak

MartinNowak Jan 31, 2012

Member

We should set the protection and parent of the alias so that private imports don't break again (see #674).

}
}

if (global.params.moduleDeps != NULL)
Expand Down Expand Up @@ -220,7 +225,7 @@ void Import::semantic(Scope *sc)
{
for (size_t i = 0; i < packages->dim; i++)
{
Identifier *pid = packages->tdata()[i];
Identifier *pid = (*packages)[i];
ob->printf("%s.", pid->toChars());
}
}
Expand All @@ -240,8 +245,8 @@ void Import::semantic(Scope *sc)
else
ob->writebyte(',');

Identifier *name = names.tdata()[i];
Identifier *alias = aliases.tdata()[i];
Identifier *name = names[i];
Identifier *alias = aliases[i];

if (!alias)
{
Expand All @@ -253,7 +258,7 @@ void Import::semantic(Scope *sc)
}

if (aliasId)
ob->printf(" -> %s", aliasId->toChars());
ob->printf(" -> %s", aliasId->toChars());

ob->writenl();
}
Expand Down Expand Up @@ -284,16 +289,16 @@ Dsymbol *Import::search(Loc loc, Identifier *ident, int flags)
{
for (size_t i = 0; i < names.dim; i++)
{
Identifier *name = (Identifier *)names.data[i];
Identifier *alias = (Identifier *)aliases.data[i];
Identifier *name = (Identifier *)names[i];
Identifier *alias = (Identifier *)aliases[i];

if (!alias)
alias = name;

if (alias->equals(ident))
return mod->search(loc, name, flags);
}

// What should happen when renamed and selective imports are mixed?
// This makes the whole module available with the renamed id.
if (aliasId && aliasId->equals(ident))
Expand Down Expand Up @@ -341,7 +346,7 @@ void Import::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
if (packages && packages->dim)
{
for (size_t i = 0; i < packages->dim; i++)
{ Identifier *pid = packages->tdata()[i];
{ Identifier *pid = (*packages)[i];

buf->printf("%s.", pid->toChars());
}
Expand Down
3 changes: 2 additions & 1 deletion src/import.h
@@ -1,6 +1,6 @@

// Compiler implementation of the D programming language
// Copyright (c) 1999-2007 by Digital Mars
// Copyright (c) 1999-2012 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
Expand Down Expand Up @@ -28,6 +28,7 @@ struct HdrGenState;

struct Import : Dsymbol
{
// isstatic import aliasId = packages.id;
Identifiers *packages; // array of Identifier's representing packages
Identifier *id; // module Identifier
Identifier *aliasId;
Expand Down

0 comments on commit df5d8fa

Please sign in to comment.