Mercurial > projects > ldc
diff dmd/expression.c @ 639:8aebdf56c455
Move check for access of context for nested class from backend into frontend.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Thu, 02 Oct 2008 23:12:19 +0200 |
parents | 4435f57956e7 |
children | eef8ac26c66c |
line wrap: on
line diff
--- a/dmd/expression.c Thu Oct 02 03:38:29 2008 +0200 +++ b/dmd/expression.c Thu Oct 02 23:12:19 2008 +0200 @@ -3370,6 +3370,7 @@ */ Dsymbol *s = cd->toParent2(); ClassDeclaration *cdn = s->isClassDeclaration(); + FuncDeclaration *fdn = s->isFuncDeclaration(); //printf("cd isNested, cdn = %s\n", cdn ? cdn->toChars() : "null"); if (cdn) @@ -3421,6 +3422,22 @@ } else if (thisexp) error("e.new is only for allocating nested classes"); + else if (fdn) + { + // make sure the parent context fdn of cd is reachable from sc + for (Dsymbol *sp = sc->parent; 1; sp = sp->parent) + { + if (fdn == sp) + break; + FuncDeclaration *fsp = sp ? sp->isFuncDeclaration() : NULL; + if (!sp || (fsp && fsp->isStatic())) + { + error("outer function context of %s is needed to 'new' nested class %s", fdn->toPrettyChars(), cd->toPrettyChars()); + break; + } + } + + } } else if (thisexp) error("e.new is only for allocating nested classes");