From 243146199fac706e8314cedaf4a2011bc614f6b6 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Thu, 12 Sep 2013 13:47:54 +0200 Subject: [PATCH] Function literals start again at nesting depth zero. GitHub: Fixes #447. --- gen/nested.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gen/nested.cpp b/gen/nested.cpp index 5aee6af4..fe79627d 100644 --- a/gen/nested.cpp +++ b/gen/nested.cpp @@ -319,7 +319,13 @@ static void DtoCreateNestedContextType(FuncDeclaration* fd) { LLStructType* innerFrameType = NULL; unsigned depth = -1; - if (!fd->isStatic()) { + + // Static functions and function (not delegate) literals don't allow + // access to a parent context, even if they are nested. + const bool certainlyNewRoot = fd->isStatic() || + (fd->isFuncLiteralDeclaration() && + static_cast(fd)->tok == TOKfunction); + if (!certainlyNewRoot) { if (FuncDeclaration* parfd = getParentFunc(fd, true)) { // Make sure the parent has already been analyzed. DtoCreateNestedContextType(parfd);