On Saturday, 14 June 2025 at 02:16:58 UTC, Andrey Zherikov wrote:
On Saturday, 14 June 2025 at 02:10:03 UTC, monkyyy wrote:
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;
}
```

Modified your example a bit.
This works:
```d
mixin template f(void function(int) F) { void s1() {"void".writeln; } } mixin template f(int function(int) F) { void s2() {"int".writeln; } }

void main()
{
mixin f!((_) {});
mixin f!((_) => 0);

    s1();
    s2();
}
```

This does not:
```d
mixin template f(void function(int) F) { void s1() {"void".writeln; } } mixin template f(int function(int) F) { void s2() {"int".writeln; } }

mixin f!((_) {});
mixin f!((_) => 0); // Error: cannot return non-void from `void` function

void main()
{
    s1();
    s2();
}
```

```d
import std;
mixin template f(int function(int) F){}
mixin template f(void function(int) F){unittest{"void".writeln;}}

//mixin f!((_){}); //FAILS


mixin template g(void function(int) F){unittest{"void".writeln;}}
mixin template g(int function(int) F){}

mixin g!((_){});  //works
```
this example makes it purely a compiler bug

I cant escape any useful information(I tried `typeof(return)`), seems to be limited to just void return functions

Reply via email to