On the subject of error messages

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Mon May 15 13:55:35 PDT 2017


On 5/15/17 4:24 PM, Stanislav Blinov wrote:
> On Monday, 15 May 2017 at 19:44:11 UTC, Steven Schveighoffer wrote:

>> It has to know. It has to evaluate the boolean to see if it should
>> compile! The current situation would be like the compiler saying
>> there's an error in your code, but won't tell you the line number.
>> Surely it knows.
>
> It "knows" it evaluated false. It doesn't know how to give user a
> digestible hint to make that false go away.

I'm going to snip away pretty much everything else and focus on this.

The compiler absolutely 100% knows, and can demonstrate, exactly why a 
template constraint failed. We don't have to go any further, or make 
suggestions about how to fix it.

Just output what exactly is wrong, even if you have to recurse into the 
depths of some obscure template isXXX, and all it's recursively called 
templates, I can get the correct determination of where either my type 
isn't right, or the constraint isn't right.

Essentially, the compiler can write "good enough" messages such that 
both an IDE and a person can understand it. That's all we need. We don't 
need to translate is(T == string) into "T should be a string" for people 
to get the meaning.

All we get today is "it didn't work". We can do better: "it didn't work 
because ...", and all existing template constraints magically get better 
error messages.

-Steve


More information about the Digitalmars-d mailing list