On Saturday, 14 June 2025 at 00:02:32 UTC, Andrey Zherikov wrote:
The simplest code that shows the issue:
```d
struct S{}

template f(void function(S) F) {}
template f(int function(S) F) {}

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

If I swap `template f` declarations:
```d
struct S{}

template f(int function(S) F) {}
template f(void function(S) F) {}

mixin f!((_) {}); // Error: function `onlineapp.__lambda_L8_C10(__T1)(_)` has no `return` statement, but is expected to return a value of type `int`
                  // mixin f!((_) {});
                  //          ^
                  //         while looking for match for `f!((_)
                  // {
                  // }
                  // )`
                  // mixin f!((_) {});
                  // ^
mixin f!((_) => 0);
```

But if I remove `S` from template parameters, everything works:
```d
template f(int function() F) {}
template f(void function() F) {}

mixin f!(() {});
mixin f!(() => 0);
```

Is this a bug somewhere in compiler or in my code?

I believe every change in compilation from (top level) declaration order is considered a compiler bug

However, I see.... Allot of issues with this code, Id want to see something near functional code around this subject; its worth poking, but its possible every possible way to make this code work would eliminate the pattern here

for example this compiles:
```d
import std;
struct S{}
template f(void function(S) F) {alias f=void;}
template f(int function(S) F) {alias f=int;}

unittest{
        alias a=f!((_) {});
        alias b=f!((_) => 0);
        a.stringof.writeln;
        b.stringof.writeln;
}
```

mixin templates vs declaration templates was a bad decision in my opinion but thats old news.

Reply via email to