Proposal: prettify template constraints failure messages
Dmitry Olshansky
dmitry.olsh at gmail.com
Fri Jan 4 06:16:44 PST 2013
I'm reposting message from Don Clugston. Somehow it's not on the list
and reply-to email address looks inaccessible.
On 02/01/13 22:25, Dmitry Olshansky wrote:
> The proposal is to extend template constraint from:
>
> if(<expr>)
> to
> if(<expr>; <message-expr>)
>
> Where the <message-expr> is CTFE-able expression with type string.
>
> The message-expr yields a hint string for compiler to show when
> instantiation failed instead of full expression that failed. It has to
> be CTFE-able even if template instantiation never actually fails.
>
> The original full expression verbose behavior can be restored if desired
> with "verbose" compiler switch. "Verbose template instantiation failure
> switch" can be later be further enhanced to detect which sub-expressions
> are false for each candidate template.
I think we should just introduce an "else" or "default" constraint. For
example:
void chain(Ranges...)(Ranges rs) default
{
static assert("std.range.chain requires: Any number of Input Ranges
all having a common type among types of their elements.");
}
ie, the default is used only if all template constraints fail.
/end of message
Which could be a more coherent way to solve it. The problem I see is
that messages are disconnected from signatures of failed templates (that
can change later and then message is easily out sync).
Either way what about just removing the constraints on the second error
message here:
bug.d(11): Error: template std.range.chain does not match any function
template declaration. Candidates are:
std/range.d(2018): std.range.chain(Ranges...)(Ranges rs) if
(Ranges.length > 0 && allSatisfy!(isInputRange, staticMap!(Unqual,
Ranges)) && !is(CommonType!(staticMap!(ElementType, staticMap!(Unqual,
Ranges))) == void))
That was the first, it list candidates. It's relatively new thing, nice
to have it.
bug.d(11): Error: template std.range.chain(Ranges...)(Ranges rs) if
(Ranges.length > 0 && allSatisfy!(isInputRange, staticMap!(Unqual,
Ranges)) && !is(CommonType!(staticMap!(ElementType, staticMap!(Unqual,
Ranges))) == void)) cannot deduce template function from argument types
!()(MapResult!(__lambda2, Foo[]),string)
The second need not to realist constraints here, they are obvious from
above, what needed is the last line - template arguments. So just make it:
bug.d(11): Error: template std.range.chain(Ranges...)(Ranges rs) cannot
deduce template function from argument types !()(MapResult!(__lambda2,
Foo[]),string)
Bugzilla worthy?
--
Dmitry Olshansky
More information about the Digitalmars-d
mailing list