struct S(T, T delegate(uint idx) supplier) { } auto make1(T, T delegate(uint idx) supplier)() { enum local = supplier; // allows to avoid an error S!(T, local) ret; return ret; } auto make2(T, T delegate(uint idx) supplier)() { S!(T, supplier) ret; // Error: template instance S!(uint, __dgliteral1) does not match template declaration S(T, uint delegate(uint idx) supplier) return ret; } unittest { enum dg = delegate(uint idx) => idx; S!(uint, dg) s; auto v = make1!(uint, dg)(); v = make2!(uint, dg)(); // throws compilation error } DMD32 D Compiler v2.069.0
With a debug build dmd, the test case will hit a dmd internal assertion. DMD v2.069 DEBUG core.exception.AssertError@dstruct.d(524): Assertion failure ---------------- 0x0058599B in _d_assert 0x0044BB66 in StructDeclaration at c:\d2home\dmd2\src\dmd\src\dstruct.d(524) 0x0045D4FD in TemplateInstance at c:\d2home\dmd2\src\dmd\src\dtemplate.d(7557) 0x0045D554 in TemplateInstance at c:\d2home\dmd2\src\dmd\src\dtemplate.d(7573) 0x00459E8E in TemplateInstance at c:\d2home\dmd2\src\dmd\src\dtemplate.d(5769) 0x0045A377 in TemplateInstance at c:\d2home\dmd2\src\dmd\src\dtemplate.d(5956) 0x004BA921 in TypeInstance at c:\d2home\dmd2\src\dmd\src\mtype.d(7381) 0x004BA9CE in TypeInstance at c:\d2home\dmd2\src\dmd\src\mtype.d(7403) 0x00429769 in VarDeclaration at c:\d2home\dmd2\src\dmd\src\declaration.d(1153) 0x0046E03F in DeclarationExp at c:\d2home\dmd2\src\dmd\src\expression.d(6590) 0x004DBA33 in ExpStatement at c:\d2home\dmd2\src\dmd\src\statement.d(1143) 0x004DC36E in CompoundStatement at c:\d2home\dmd2\src\dmd\src\statement.d(1421) 0x00487619 in FuncDeclaration at c:\d2home\dmd2\src\dmd\src\func.d(1604) 0x0045A62C in TemplateInstance at c:\d2home\dmd2\src\dmd\src\dtemplate.d(6048) 0x0045D5A4 in TemplateInstance at c:\d2home\dmd2\src\dmd\src\dtemplate.d(7588) 0x0045A00A in TemplateInstance at c:\d2home\dmd2\src\dmd\src\dtemplate.d(5838) 0x0045A377 in TemplateInstance at c:\d2home\dmd2\src\dmd\src\dtemplate.d(5956) 0x0046B0E3 in ScopeExp at c:\d2home\dmd2\src\dmd\src\expression.d(5323) 0x00474002 in CallExp at c:\d2home\dmd2\src\dmd\src\expression.d(8939) 0x0049C6FF in ExpInitializer at c:\d2home\dmd2\src\dmd\src\init.d(775) 0x004296A8 in VarDeclaration at c:\d2home\dmd2\src\dmd\src\declaration.d(1129) 0x0046E03F in DeclarationExp at c:\d2home\dmd2\src\dmd\src\expression.d(6590) 0x004DBA33 in ExpStatement at c:\d2home\dmd2\src\dmd\src\statement.d(1143) 0x004DC36E in CompoundStatement at c:\d2home\dmd2\src\dmd\src\statement.d(1421) 0x00487619 in FuncDeclaration at c:\d2home\dmd2\src\dmd\src\func.d(1604) 0x00444774 in Module at c:\d2home\dmd2\src\dmd\src\dmodule.d(1038) 0x004ACEEA in tryMain at c:\d2home\dmd2\src\dmd\src\mars.d(1515) 0x004AD79F in _Dmain at c:\d2home\dmd2\src\dmd\src\mars.d(1693) 0x00586C36 in D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv 0x00586C0B in void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll() 0x00586B23 in _d_run_main 0x004ADAE4 in main 0x0059AFCD in mainCRTStartup 0x7595337A in BaseThreadInitThunk 0x776D9882 in RtlInitializeExceptionChain 0x776D9855 in RtlInitializeExceptionChain
https://github.com/D-Programming-Language/dmd/pull/5275
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/d8eb30c8da082cb7533a95c3930be46f818edadf fix Issue 15352 - template arguments matching error with delegates 1. `match()` function relies on `Expression.equals()`. Add `FuncExp.equals` for the identity comparison of two `FuncExp`s. 2. When a `FuncLiteralDeclaration` is listed directly in template arguments, it needs to be converted to `FuncExp` to be able to match `TemplateValueParameter`. https://github.com/D-Programming-Language/dmd/commit/a498e675b5a685494a2168a9438fe34b0467650a Merge pull request #5275 from 9rnsr/fix15352 Issue 15352 - template arguments matching error with delegates
Commits pushed to stable at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/d8eb30c8da082cb7533a95c3930be46f818edadf fix Issue 15352 - template arguments matching error with delegates https://github.com/D-Programming-Language/dmd/commit/a498e675b5a685494a2168a9438fe34b0467650a Merge pull request #5275 from 9rnsr/fix15352