[Issue 11685] New: template opDispatch rejects-valid.
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Dec 4 14:05:48 PST 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11685
Summary: template opDispatch rejects-valid.
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: john.loughran.colvin at gmail.com
--- Comment #0 from John Colvin <john.loughran.colvin at gmail.com> 2013-12-04 22:05:46 GMT ---
this code:
template PartialApply(alias F, uint argLoc, Arg ...)
if(Arg.length == 1)
{
pragma(msg, "\nPartialApply!(", __traits(identifier, F),", ", argLoc, ", ",
Arg[0], ");\n");
template PartialApply(L ...)
{
pragma(msg, "\nPartialApply!(", __traits(identifier, F),", ", argLoc,
", ", Arg[0], ").PartialApply!(", L, ");\n");
alias PartialApply = F!(L[0 .. argLoc], Arg, L[argLoc .. $]);
}
}
struct Pack(T...)
{
template opDispatch(string s)
{
pragma(msg, "\n",typeof(this),".opDispatch!(\"",s,"\");\n");
mixin("alias opDispatch = PartialApply!(." ~ s ~ ", 0, typeof(this));");
}
}
struct asArg(T, uint argIndex)
{
pragma(msg, "\n", typeof(this));
pragma(msg, "asArg!(", T, ", ", argIndex, ");\n");
template opDispatch(string s)
{
pragma(msg, "\n",typeof(this),".opDispatch!(\"", s, "\");\n");
mixin("alias opDispatch = PartialApply!(." ~ s ~ ", " ~ argIndex.stringof ~
", T);");
}
}
unittest
{
pragma(msg, "\n" ,Pack!(1,2,3).asArg!(1).Pack!(0), "\n");
alias A = Pack!(1,2,3).asArg!(1).Pack!(0);
}
produces this output:
$ dmd -unittest -c break.d
Pack!(1, 2, 3).opDispatch!("asArg");
PartialApply!(asArg, 0u, Pack!(1, 2, 3));
PartialApply!(asArg, 0u, Pack!(1, 2, 3)).PartialApply!(tuple(1));
F!(Pack!(1, 2, 3), 1)
asArg!(Pack!(1, 2, 3), 1u);
F!(Pack!(1, 2, 3), 1).opDispatch!("Pack");
PartialApply!(Pack, 1u, Pack!(1, 2, 3));
PartialApply!(Pack, 1u, Pack!(1, 2, 3)).PartialApply!(tuple(0));
F!(0, Pack!(1, 2, 3))
break.d(12): Error: struct break.Pack!(1, 2, 3).Pack template identifier
'asArg' is not a member of 'struct Pack'
break.d(12): Error: struct break.Pack!(1, 2, 3).Pack template identifier
'asArg' is not a member of 'struct Pack'
A few things jump out, other than the (hopefully) obvious rejects-valid:
1) The two lines
F!(Pack!(1, 2, 3), 1)
asArg!(Pack!(1, 2, 3), 1u);
should be the same. How can a struct not be able to work out it's own
typeof(this)?
2) There is an extra new-line at the top of the output and a missing new-line
between the last two pragma printouts.
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list