diff --git a/compiler/src/dmd/templatesem.d b/compiler/src/dmd/templatesem.d index 304a7a8fd1f2..0067ee820952 100644 --- a/compiler/src/dmd/templatesem.d +++ b/compiler/src/dmd/templatesem.d @@ -3282,6 +3282,21 @@ bool needsCodegen(TemplateInstance ti) return false; } + if (ti.enclosing) + { + if (auto fd = ti.enclosing.isFuncDeclaration()) + { + if (auto fld = fd.isFuncLiteralDeclaration()) + { + if (fld.tookAddressOf == 0 && fld.tok != TOK.reserved) + { + ti.minst = null; // mark as speculative + return false; + } + } + } + } + // This should only be called on the primary instantiation. assert(ti is ti.inst); diff --git a/compiler/test/runnable/issue22848.d b/compiler/test/runnable/issue22848.d new file mode 100644 index 000000000000..13b632513dd3 --- /dev/null +++ b/compiler/test/runnable/issue22848.d @@ -0,0 +1,20 @@ +@" +// Test for Issue 22848 +// Undefined reference to static function in unused mixin lambda + +mixin template Main(alias mainFunction) {} + +mixin Main!( + () + { + static bool pred(char c) => false; + accept!pred; + } +); + +char accept(alias pred)() => pred(0); + +void main() +{ +} +"@