diff options
Diffstat (limited to 'gcc/d/dmd/expressionsem.c')
-rw-r--r-- | gcc/d/dmd/expressionsem.c | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/gcc/d/dmd/expressionsem.c b/gcc/d/dmd/expressionsem.c index c23e332..781bd3e 100644 --- a/gcc/d/dmd/expressionsem.c +++ b/gcc/d/dmd/expressionsem.c @@ -1758,15 +1758,30 @@ public: else { // Disallow shadowing - for (Scope *scx = sc->enclosing; scx && scx->func == sc->func; scx = scx->enclosing) + for (Scope *scx = sc->enclosing; scx && (scx->func == sc->func || (scx->func && sc->func->fes)); scx = scx->enclosing) { Dsymbol *s2; if (scx->scopesym && scx->scopesym->symtab && (s2 = scx->scopesym->symtab->lookup(s->ident)) != NULL && s != s2) { - e->error("%s %s is shadowing %s %s", s->kind(), s->ident->toChars(), s2->kind(), s2->toPrettyChars()); - return setError(); + // allow STClocal symbols to be shadowed + // TODO: not reallly an optimal design + Declaration *decl = s2->isDeclaration(); + if (!decl || !(decl->storage_class & STClocal)) + { + if (sc->func->fes) + { + e->deprecation("%s `%s` is shadowing %s `%s`. Rename the `foreach` variable.", + s->kind(), s->ident->toChars(), s2->kind(), s2->toPrettyChars()); + } + else + { + e->error("%s %s is shadowing %s %s", + s->kind(), s->ident->toChars(), s2->kind(), s2->toPrettyChars()); + return setError(); + } + } } } } @@ -7930,6 +7945,12 @@ public: if (f1 || f2) return setError(); + if (exp->e1->op == TOKtype || exp->e2->op == TOKtype) + { + result = exp->incompatibleTypes(); + return; + } + exp->type = Type::tbool; if (exp->e1->type != exp->e2->type && exp->e1->type->isfloating() && exp->e2->type->isfloating()) |