Skip to content

Commit

Permalink
Merge pull request #1665 from 9rnsr/fix9514
Browse files Browse the repository at this point in the history
Issue 9514 - "template instance … is not an alias"
  • Loading branch information
WalterBright committed Feb 16, 2013
1 parent df3d214 commit 0efbffd
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/declaration.c
Expand Up @@ -19,6 +19,7 @@
#include "scope.h"
#include "aggregate.h"
#include "module.h"
#include "import.h"
#include "id.h"
#include "expression.h"
#include "statement.h"
Expand Down Expand Up @@ -414,6 +415,7 @@ AliasDeclaration::AliasDeclaration(Loc loc, Identifier *id, Type *type)
this->loc = loc;
this->type = type;
this->aliassym = NULL;
this->import = NULL;
this->htype = NULL;
this->haliassym = NULL;
this->overnext = NULL;
Expand All @@ -429,6 +431,7 @@ AliasDeclaration::AliasDeclaration(Loc loc, Identifier *id, Dsymbol *s)
this->loc = loc;
this->type = NULL;
this->aliassym = s;
this->import = NULL;
this->htype = NULL;
this->haliassym = NULL;
this->overnext = NULL;
Expand Down Expand Up @@ -673,6 +676,13 @@ Dsymbol *AliasDeclaration::toAlias()
}
else if (aliassym || type->deco)
; // semantic is already done.
else if (import)
{
/* If this is an internal alias for selective import,
* resolve it under the correct scope.
*/
import->semantic(NULL);
}
else if (scope)
semantic(scope);
Dsymbol *s = aliassym ? aliassym->toAlias() : this;
Expand Down
1 change: 1 addition & 0 deletions src/declaration.h
Expand Up @@ -234,6 +234,7 @@ struct AliasDeclaration : Declaration
{
Dsymbol *aliassym;
Dsymbol *overnext; // next in overload list
Dsymbol *import; // !=NULL if unresolved internal alias for selective import
int inSemantic;

AliasDeclaration(Loc loc, Identifier *ident, Type *type);
Expand Down
15 changes: 12 additions & 3 deletions src/import.c
Expand Up @@ -180,6 +180,11 @@ void Import::semantic(Scope *sc)
{
//printf("Import::semantic('%s')\n", toChars());

if (scope)
{ sc = scope;
scope = NULL;
}

// Load if not already done so
if (!mod)
{ load(sc);
Expand Down Expand Up @@ -234,14 +239,17 @@ void Import::semantic(Scope *sc)
sc->protection = PROTpublic;
#endif
for (size_t i = 0; i < aliasdecls.dim; i++)
{ Dsymbol *s = aliasdecls[i];
{ AliasDeclaration *ad = aliasdecls[i];

//printf("\tImport alias semantic('%s')\n", s->toChars());
if (mod->search(loc, names[i], 0))
s->semantic(sc);
{
ad->semantic(sc);
ad->import = NULL; // forward reference resolved
}
else
{
s = mod->search_correct(names[i]);
Dsymbol *s = mod->search_correct(names[i]);
if (s)
mod->error(loc, "import '%s' not found, did you mean '%s %s'?", names[i]->toChars(), s->kind(), s->toChars());
else
Expand Down Expand Up @@ -374,6 +382,7 @@ int Import::addMember(Scope *sc, ScopeDsymbol *sd, int memnum)

TypeIdentifier *tname = new TypeIdentifier(loc, name);
AliasDeclaration *ad = new AliasDeclaration(loc, alias, tname);
ad->import = this;
result |= ad->addMember(sc, sd, memnum);

aliasdecls.push(ad);
Expand Down
22 changes: 22 additions & 0 deletions test/compilable/fwdref9514a.d
@@ -0,0 +1,22 @@
// PERMUTE_ARGS:
// REQUIRED_ARGS: -o-

template TStructHelpers()
{
void opEquals(Foo)
{
auto n = FieldNames!();
}
}

struct Foo
{
mixin TStructHelpers!();
}

import imports.fwdref9514 : find; // selective import without aliasing

template FieldNames()
{
static if (find!`true`([1])) enum int FieldNames = 1;
}
22 changes: 22 additions & 0 deletions test/compilable/fwdref9514b.d
@@ -0,0 +1,22 @@
// PERMUTE_ARGS:
// REQUIRED_ARGS: -o-

template TStructHelpers()
{
void opEquals(Foo)
{
auto n = FieldNames!();
}
}

struct Foo
{
mixin TStructHelpers!();
}

import imports.fwdref9514 : foo = find; // selective import with aliasing

template FieldNames()
{
static if (foo!`true`([1])) enum int FieldNames = 1;
}
4 changes: 4 additions & 0 deletions test/compilable/imports/fwdref9514.d
@@ -0,0 +1,4 @@
bool find(alias pred, R)(R range)
{
return true;
}

0 comments on commit 0efbffd

Please sign in to comment.