diff --git a/src/expression.c b/src/expression.c index d7aee433538e..fe4c4d884e2a 100644 --- a/src/expression.c +++ b/src/expression.c @@ -6155,15 +6155,18 @@ Expression *DeclarationExp::semantic(Scope *sc) if (ad) { if (ad->decl && ad->decl->dim == 1) - { s = (*ad->decl)[0]; + { + s = (*ad->decl)[0]; continue; } } break; } - if (s->isVarDeclaration()) - { // Do semantic() on initializer first, so: + VarDeclaration *v = s->isVarDeclaration(); + if (v) + { + // Do semantic() on initializer first, so: // int a = a; // will be illegal. declaration->semantic(sc); @@ -6176,14 +6179,17 @@ Expression *DeclarationExp::semantic(Scope *sc) if (s->ident) { if (!sc->insert(s)) - { error("declaration %s is already defined", s->toPrettyChars()); + { + error("declaration %s is already defined", s->toPrettyChars()); return new ErrorExp(); } else if (sc->func) { - if ( (s->isFuncDeclaration() || s->isTypedefDeclaration() || - s->isAggregateDeclaration() || s->isEnumDeclaration() || - s->isInterfaceDeclaration()) && + if ((s->isFuncDeclaration() || + s->isTypedefDeclaration() || + s->isAggregateDeclaration() || + s->isEnumDeclaration() || + v && v->isDataseg()) && // Bugzilla 11720 !sc->func->localsymtab->insert(s)) { error("declaration %s is already defined in another scope in %s", @@ -6191,11 +6197,11 @@ Expression *DeclarationExp::semantic(Scope *sc) return new ErrorExp(); } else - { // Disallow shadowing - + { + // Disallow shadowing for (Scope *scx = sc->enclosing; scx && scx->func == sc->func; scx = scx->enclosing) - { Dsymbol *s2; - + { + Dsymbol *s2; if (scx->scopesym && scx->scopesym->symtab && (s2 = scx->scopesym->symtab->lookup(s->ident)) != NULL && s != s2) diff --git a/test/fail_compilation/fail11720.d b/test/fail_compilation/fail11720.d new file mode 100644 index 000000000000..8ad1d862d6bd --- /dev/null +++ b/test/fail_compilation/fail11720.d @@ -0,0 +1,33 @@ +// REQUIRED_ARGS: -o- +/* +TEST_OUTPUT: +--- +fail_compilation/fail11720.d(23): Error: declaration fail11720.foo!().foo.temp is already defined in another scope in foo +fail_compilation/fail11720.d(13): Error: template instance fail11720.foo!() error instantiating +fail_compilation/fail11720.d(31): Error: declaration fail11720.bar.temp is already defined in another scope in bar +--- +*/ + +void main() +{ + foo(); + bar(); +} + +alias TypeTuple(T...) = T; + +void foo()() +{ + foreach (T; TypeTuple!(int, double)) + { + static temp = T.stringof; + } +} + +void bar() +{ + foreach (T; TypeTuple!(int, double)) + { + static temp = T.stringof; + } +}