Difference in compiletime vs compiletime or compiler bug?
Sjoerd Nijboer
dlang at sjoerdnijboer.com
Fri Dec 27 18:22:10 UTC 2019
I've got a snippet of code which I have narrowed down to the
following:
'import std.stdio;
enum string[] mixins = ["public bool qux(int i, char c)
{
throw new Exception(\"not implemented\");
// Add all arguments to a struct and serialize
that struct.
};", "
public bool qux(string s)
{
throw new Exception(\"not implemented\");
// Add all arguments to a struct and serialize
that struct.
};
"];
struct C
{
static foreach (m; mixins)
{
mixin mix!m;
}
}
mixin template mix(string s)
{
mixin(s);
}
void main()
{
import std.traits : ReturnType;
auto c = C();
pragma(msg, c.qux.mangleof); // writes 'v' to the console
pragma(msg, ReturnType!(c.qux));
}'
The exact error this returns is as follows:
'Error: template instance std.traits.ReturnType!(qux) does not
match template declaration ReturnType(func...)
with func = (qux)
must satisfy the following constraint:
isCallable!func
source/app.d(34,2): while evaluating pragma(msg,
ReturnType!(qux)
'
As far as I know, this "should" work.
When I delete one of the functions out of the mixin it suddenly
compiles with a mangled name, but when I place the second
function in there it won't.
When calling the mixin directly instead of through the template
mixin it breaks with thesame error message.
I don't know if this an actual compiler bug or if this is me not
properly understanding D.
I'm using DMD64 D Compiler v2.089.1
Any help is appreciated.
More information about the Digitalmars-d-learn
mailing list