Mixin template parameter overloading bug?

monkyyy crazymonkyyy at gmail.com
Sat Jun 14 02:10:03 UTC 2025


On Saturday, 14 June 2025 at 01:46:31 UTC, Andrey Zherikov wrote:
> On Saturday, 14 June 2025 at 00:02:32 UTC, Andrey Zherikov 
> wrote:
> Simplified test case a bit more.
> This works:
> ```d
> template f(void function(int) F) {}
> template f(int function(int) F) {}
>
> mixin f!((int _) {});
> mixin f!((int _) => 0);
>
> mixin f!((int) {});
> mixin f!((int) => 0);
>
> mixin f!((_) {});
> mixin f!((_) => 0);  // Error: cannot return non-void from 
> `void` function
> ```
>
> Can anyone explain why adding type of the parameter in lambda 
> (`int`) makes this working?

https://dlang.org/spec/template-mixin.html

Your still mixing syntax; mixin templates are suppose to be a 
separate system according to the spec.

```d
import std;
void f(int function(int) F)(){"int".writeln;}
void f(void function(int) F)(){"void".writeln;}
unittest{
	f!((_) {});
	f!((_) => 0);
}

mixin template g(int function(int) F){string s1="int";}
mixin template g(void function(int) F){string s2="void";}
unittest{
	mixin g!((_) {});
	mixin g!((_) => 0);
	s1.writeln;
	s2.writeln;
}
```


More information about the Digitalmars-d-learn mailing list