Skip to content

Commit

Permalink
Merge pull request #2705 from 9rnsr/fix11385
Browse files Browse the repository at this point in the history
Issue 11385 - XXX is a nested function and cannot be accessed from XXX
  • Loading branch information
WalterBright committed Nov 8, 2013
2 parents d1cc3e7 + 42b6930 commit 7d308c5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/func.c
Expand Up @@ -2982,8 +2982,12 @@ int FuncDeclaration::getLevel(Loc loc, Scope *sc, FuncDeclaration *fd)
return level;

Lerr:
Dsymbol *p = toParent2();
while (p->toParent2()->isFuncDeclaration())
p = p->toParent2();

// Don't give error if in template constraint
if (!((sc->flags & SCOPEstaticif) && parent->isTemplateDeclaration()))
if (!(sc->flags & SCOPEstaticif) && !p->parent->isTemplateDeclaration())
{
const char *xstatic = isStatic() ? "static " : "";
// better diagnostics for static functions
Expand Down Expand Up @@ -3518,7 +3522,7 @@ void FuncDeclaration::checkNestedReference(Scope *sc, Loc loc)
FuncDeclaration *fdthis = sc->parent->isFuncDeclaration();

//printf("this = %s in [%s]\n", this->toChars(), this->loc.toChars());
//printf("fdv = %s in [%s]\n", fdv->toChars(), fdv->loc.toChars());
//printf("fdv2 = %s in [%s]\n", fdv2->toChars(), fdv2->loc.toChars());
//printf("fdthis = %s in [%s]\n", fdthis->toChars(), fdthis->loc.toChars());

if (fdv2 && fdthis && fdv2 != fdthis)
Expand All @@ -3539,8 +3543,7 @@ void FuncDeclaration::checkNestedReference(Scope *sc, Loc loc)
}
}

FuncDeclaration *fdv = toParent()->isFuncDeclaration();
fdv = toParent()->isFuncDeclaration();
FuncDeclaration *fdv = toParent2()->isFuncDeclaration();
if (fdv && fdthis && fdv != fdthis)
{
int lv = fdthis->getLevel(loc, sc, fdv);
Expand Down
22 changes: 22 additions & 0 deletions test/runnable/nested.d
Expand Up @@ -2465,6 +2465,27 @@ class C10495
}
}

/*******************************************/
// 11385

auto map11385(alias fun, R)(R range)
{
return MapResult11385!(fun, R)(range);
}
struct MapResult11385(alias fun, R)
{
R range;
auto front() { return fun(range[0]); }
}
void test11385()
{
//import std.algorithm;
static auto fun1(T)(T a) { return a * 2; }
auto fun2(T)(T a) { return a * 2; }
[1].map11385!(a=>fun1(a)); // OK
[1].map11385!(a=>fun2(a)); // NG:XXX is a nested function and cannot be accessed from XXX
}

/*******************************************/

int main()
Expand Down Expand Up @@ -2550,6 +2571,7 @@ int main()
test8832();
test9315();
test9244();
test11385();

printf("Success\n");
return 0;
Expand Down

0 comments on commit 7d308c5

Please sign in to comment.