Skip to content

Commit a5b0c04

Browse files
author
CHIKI Badreddine
committed
Fix issue 22848: Skip codegen for template instances within unreferenced lambdas
1 parent b3e02d4 commit a5b0c04

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

compiler/src/dmd/templatesem.d

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3282,6 +3282,21 @@ bool needsCodegen(TemplateInstance ti)
32823282
return false;
32833283
}
32843284

3285+
if (ti.enclosing)
3286+
{
3287+
if (auto fd = ti.enclosing.isFuncDeclaration())
3288+
{
3289+
if (auto fld = fd.isFuncLiteralDeclaration())
3290+
{
3291+
if (fld.tookAddressOf == 0 && fld.tok != TOK.reserved)
3292+
{
3293+
ti.minst = null; // mark as speculative
3294+
return false;
3295+
}
3296+
}
3297+
}
3298+
}
3299+
32853300
// This should only be called on the primary instantiation.
32863301
assert(ti is ti.inst);
32873302

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
@"
2+
// Test for Issue 22848
3+
// Undefined reference to static function in unused mixin lambda
4+
5+
mixin template Main(alias mainFunction) {}
6+
7+
mixin Main!(
8+
()
9+
{
10+
static bool pred(char c) => false;
11+
accept!pred;
12+
}
13+
);
14+
15+
char accept(alias pred)() => pred(0);
16+
17+
void main()
18+
{
19+
}
20+
"@

0 commit comments

Comments
 (0)