error diagnosis: range.algorithm(myFunc)

John Colvin via Digitalmars-d digitalmars-d at puremagic.com
Thu Dec 17 03:41:09 PST 2015


On Thursday, 17 December 2015 at 07:44:43 UTC, ZombineDev wrote:
> On Thursday, 17 December 2015 at 01:04:15 UTC, Luís Marques 
> wrote:
>> Hi,
>>
>> I often type `range.algorithm(myFunc)` instead of the correct 
>> `range.algorithm!(myFunc)`. Would it be possible to improve 
>> the error message for this? Something like the compiler spell 
>> checker, and ask "did you mean `range.algorithm!(myFunc)`?".
>>
>> That has happened sometimes with a non-UFCS call, but that's 
>> rarer, so just handling the UFCS case would bring most of the 
>> benefit, IMO.
>
> I think it's not easy to make a general checker that can sugest 
> changing a run-time argument into a compile-time one.
> A static assert should be flexible enough solution, but we 
> would need to make all of the template constraints into static 
> asserts, because otherwise the compiler will never reach the 
> static assert that would check if the type of the first 
> run-time arg is not a function.

Seems feasible to me for the compiler:

If the call doesn't compile, try moving the first argument (or 
second on a ufcs call) to be the first template argument. If that 
would compile, suggest it to the user in the error output.


More information about the Digitalmars-d mailing list