Skip to content

Commit 98a398b

Browse files
committed
fix Issue 9578 - "is a nested function and cannot be accessed from" problem
1 parent 712c3e2 commit 98a398b

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/template.c

+8
Original file line numberDiff line numberDiff line change
@@ -6197,9 +6197,17 @@ int TemplateInstance::hasNestedArgs(Objects *args)
61976197
Lsa:
61986198
sa = sa->toAlias();
61996199
TemplateDeclaration *td = sa->isTemplateDeclaration();
6200+
if (td)
6201+
{
6202+
TemplateInstance *ti = sa->toParent()->isTemplateInstance();
6203+
if (ti && ti->enclosing)
6204+
sa = ti;
6205+
}
6206+
TemplateInstance *ti = sa->isTemplateInstance();
62006207
AggregateDeclaration *ad = sa->isAggregateDeclaration();
62016208
Declaration *d = sa->isDeclaration();
62026209
if ((td && td->literal) ||
6210+
(ti && ti->enclosing) ||
62036211
#if FIXBUG8863
62046212
(ad && ad->isNested()) ||
62056213
#endif

test/runnable/template9.d

+18
Original file line numberDiff line numberDiff line change
@@ -2173,6 +2173,23 @@ void test9536()
21732173
assert(s.bar() == 84);
21742174
}
21752175

2176+
/**********************************/
2177+
// 9578
2178+
2179+
template t9578(alias f) { void tf()() { f(); } }
2180+
2181+
void g9578a(alias f)() { f(); } // Error -> OK
2182+
void g9578b(alias ti)() { ti.tf(); } // Error -> OK
2183+
2184+
void test9578()
2185+
{
2186+
int i = 0;
2187+
int m() { return i; }
2188+
2189+
g9578a!(t9578!m.tf)();
2190+
g9578b!(t9578!m)();
2191+
}
2192+
21762193
/**********************************/
21772194
// 9596
21782195

@@ -2801,6 +2818,7 @@ int main()
28012818
test9143();
28022819
test9266();
28032820
test9536();
2821+
test9578();
28042822
test9596();
28052823
test9837();
28062824
test9874();

0 commit comments

Comments
 (0)