D's greatest mistakes

Andrej Mitrovic andrej.mitrovich at gmail.com
Mon Nov 29 17:18:11 PST 2010


On 11/30/10, Simen kjaeraas <simen.kjaras at gmail.com> wrote:
> Andrej Mitrovic <andrej.mitrovich at gmail.com> wrote:
>
>>> Which error message should I show?
>>>
>> I'm not sure what you're getting at. :)
> [snip]
>> But anyway it's just an idea and I'm probably missing something
>> important, I haven't used D in a while..
>
> I believe you are missing that more templates could bear the same
> name, and they could all fail for varying reasons. In such a case,
> do you print the error messages from 100 templates and let the
> user sort through them, or do you show the error the compiler
> currently shows?
>
> I admit my example was flawed, or at least incomplete:
>
>> void foo( A )( A a )
>> constraint {
>>    isBar!A;
>> }
>>
>> void foo( B )( B a )
>> constraint {
>>    isQux!B;
>> }
>
> void main( ) {
>      int n;
>      assert( !isBar!int );
>      assert( !isQux!int );
>      foo( n );
> }
>
> The call to foo would match neither template, giving errors akin
> to this:
>
> test.d(15) Error: template instantiation foo!int failed.
> test.d(3)   Error: template constraint failed
> test.d(6)   Error: template constraint failed
>
> Seems good for two or three templates, but I fear this would grow
> quickly out of hand for more templates.
>
> --
> Simen
>

Ah, yeah you would be right. I'm not sure, maybe the template with the
least amount of failed statements would be displayed as a closest-but
failed-match, and others would not be shown. Otherwise we would have
error message bloat.


More information about the Digitalmars-d mailing list