Re: Simple and effective approaches to constraint error messages

2016-04-27 Thread Steven Schveighoffer via Digitalmars-d
On 4/25/16 6:14 PM, H. S. Teoh via Digitalmars-d wrote: On Mon, Apr 25, 2016 at 05:20:08PM -0400, Steven Schveighoffer via Digitalmars-d wrote: 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.

Re: Simple and effective approaches to constraint error messages

2016-04-26 Thread Timon Gehr via Digitalmars-d
On 26.04.2016 13:26, Marc Schütz wrote: Currently, there is no boolean short-cut evaluation in template constraints, see: bool foo()() { pragma(msg, "foo"); return true; } bool bar()() { pragma(msg, "bar"); return true; } void

Re: Simple and effective approaches to constraint error messages

2016-04-26 Thread Meta via Digitalmars-d
On Tuesday, 26 April 2016 at 15:56:55 UTC, Andrei Alexandrescu wrote: On 04/26/2016 11:35 AM, Meta wrote: The nice part about 1 is that every constraint gets it for free. Only if in CNF, otherwise needs changed. -- Andrei True, but I bet the majority of template constraints are in this

Re: Simple and effective approaches to constraint error messages

2016-04-26 Thread Andrei Alexandrescu via Digitalmars-d
On 04/26/2016 11:35 AM, Meta wrote: The nice part about 1 is that every constraint gets it for free. Only if in CNF, otherwise needs changed. -- Andrei

Re: Simple and effective approaches to constraint error messages

2016-04-26 Thread Meta via Digitalmars-d
On Monday, 25 April 2016 at 17:52:58 UTC, Andrei Alexandrescu wrote: Idea #2: Allow custom error messages The basic idea here is to define pragma(err, "message") as an expression that formats "message" as an error and returns false. Then we can write: R find(R, E)(R range, E elem) if

Re: Simple and effective approaches to constraint error messages

2016-04-26 Thread Atila Neves via Digitalmars-d
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: [...] I still prefer static inheritance. Having said that, I like the pragma(err) thing in the template

Re: Simple and effective approaches to constraint error messages

2016-04-26 Thread Kagamin via Digitalmars-d
https://issues.dlang.org/show_bug.cgi?id=9626 ?

Re: Simple and effective approaches to constraint error messages

2016-04-26 Thread Marc Schütz via Digitalmars-d
On Monday, 25 April 2016 at 17:52:58 UTC, Andrei Alexandrescu wrote: Idea #1: Detect and use CNF, print which clause failed I prefer this one, because it should work without modifying library or user code. Idea #2: Allow custom error messages The basic idea here is to define

Re: Simple and effective approaches to constraint error messages

2016-04-25 Thread H. S. Teoh via Digitalmars-d
On Mon, Apr 25, 2016 at 05:20:08PM -0400, Steven Schveighoffer via Digitalmars-d wrote: > 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

Re: Simple and effective approaches to constraint error messages

2016-04-25 Thread QAston via Digitalmars-d
On Monday, 25 April 2016 at 17:52:58 UTC, Andrei Alexandrescu wrote: Idea #1: Detect and use CNF, print which clause failed CNF (https://en.wikipedia.org/wiki/Conjunctive_normal_form) is a formula shape in Boolean logic that groups clauses into a top-level conjunction. The compiler

Re: Simple and effective approaches to constraint error messages

2016-04-25 Thread Steven Schveighoffer via Digitalmars-d
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

Re: Simple and effective approaches to constraint error messages

2016-04-25 Thread Andrei Alexandrescu via Digitalmars-d
On 04/25/2016 04:50 PM, Sebastiaan Koppe wrote: What about overloaded functions with complex constraints? How would the errors look when none of the overloaded constraints fully match? Print reason for each. -- Andrei

Re: Simple and effective approaches to constraint error messages

2016-04-25 Thread Sebastiaan Koppe via Digitalmars-d
On Monday, 25 April 2016 at 17:52:58 UTC, Andrei Alexandrescu wrote: Destroy! Andrei What about overloaded functions with complex constraints? How would the errors look when none of the overloaded constraints fully match? auto fun(T)(T t) if (hasWheels!T && canFly!T) {} auto fun(T)(T t)

Re: Simple and effective approaches to constraint error messages

2016-04-25 Thread Andrei Alexandrescu via Digitalmars-d
On 04/25/2016 02:17 PM, Daniel N wrote: 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

Re: Simple and effective approaches to constraint error messages

2016-04-25 Thread Daniel N via Digitalmars-d
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

Re: Simple and effective approaches to constraint error messages

2016-04-25 Thread Adam D. Ruppe via Digitalmars-d
On Monday, 25 April 2016 at 17:52:58 UTC, Andrei Alexandrescu wrote: /d935/f781.d(16): Error: template f781.find cannot deduce function from argument types !()(NotARange, int), candidates are: /d935/f781.d(3): f781.find(R, E)(R range, E elem) constraint failed: isInputRange!NotARange This