Thread overview
error diagnosis: range.algorithm(myFunc)
Dec 17, 2015
Luís Marques
Dec 17, 2015
ZombineDev
Dec 17, 2015
John Colvin
Dec 17, 2015
Luís Marques
December 17, 2015
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.
December 17, 2015
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.
December 17, 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.
December 17, 2015
On Thursday, 17 December 2015 at 11:41:09 UTC, John Colvin wrote:
> 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.

That's more or less the first implementation that came to my mind, too.