Simple and effective approaches to constraint error messages
Steven Schveighoffer via Digitalmars-d
digitalmars-d at puremagic.com
Mon Apr 25 14:20:08 PDT 2016
On 4/25/16 1:52 PM, Andrei Alexandrescu wrote:
> It's been long asked in our community that failing template constraints
> issue better error messages. Consider:
I like the first option. However, I think it should be deeper than that.
Sometimes you have code that you are sure matches one of the constraints
(e.g. isInputRange), but for some reason it doesn't. Sure, it's good to
know that your struct that looks exactly like an input range isn't an
input range, but to know why would be better.
I realize that more context for an error may be too verbose, but an
option to have the compiler tell you exactly why it is stopping
compilation is good when you can't figure out the obvious reason.
So for instance, having it say "constraint failed:
isInputRange!NotARange" is good, but if you pass some parameter it says
something like: "constraint failed: isInputRange!NotARange,
std.range.primitives:146 failed to compile: x.front
or something like that. This is a previous post related to this issue:
http://forum.dlang.org/post/m4nnrk$1ml5$1@digitalmars.com
-Steve
More information about the Digitalmars-d
mailing list