Simple and effective approaches to constraint error messages
Daniel N via Digitalmars-d
digitalmars-d at puremagic.com
Mon Apr 25 11:17:58 PDT 2016
On Monday, 25 April 2016 at 17:52:58 UTC, Andrei Alexandrescu
wrote:
> It's been long asked in our community that failing template
> constraints issue better error messages. Consider:
>
> This program uses no constraints. Attempting to compile yields:
>
> /d240/f632.d(3): Error: no property 'empty' for type 'NotARange'
> /d240/f632.d(3): Error: no property 'popFront' for type
> 'NotARange'
> /d240/f632.d(4): Error: no property 'front' for type 'NotARange'
> /d240/f632.d(13): Error: template instance
> f632.find!(NotARange, int) error instantiating
>
> which is actually quite informative if you're okay with error
> messages pointing inside the template body (which is presumably
> a preexisting library) instead of the call site.
>
It should be possible to generate those errors even with
constraints and no library update.
Currently when the compiler is in "__traits(compiles" or
"is(typeof" mode, it simply gags all errors, if it instead would
save them to a side buffer. Later the entire side-buffer could be
dumped after a template constraint totally failed. If a
constraint succeeds the buffer is cleared.
More information about the Digitalmars-d
mailing list