Better error messages - from reddit

Walter Bright newshound2 at digitalmars.com
Tue Mar 5 01:07:08 UTC 2019


On 3/4/2019 9:19 AM, H. S. Teoh wrote:
> No, I think the original reasoning was that allowing arbitrary boolean
> clauses in sig constraints is more expressive than allowing only a
> subset of expressions (e.g., implementsTrait!T).

That's correct. For example, you could have a constraint that required an odd 
integer.

Use of `static if` and `pragma(msg)` can be used to generate custom error messages:

     static if (!isInputRange(r)) pragma(msg, r, " must be an Input Range");

This is ultimately far more powerful than anything the compiler can come up 
with, because it can be about the user's context, not the compiler's.


More information about the Digitalmars-d mailing list