www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - error diagnosis: range.algorithm(myFunc)

reply =?UTF-8?B?THXDrXM=?= Marques <luis luismarques.eu> writes:
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.
Dec 16 2015
parent reply ZombineDev <valid_email he.re> writes:
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.
Dec 16 2015
parent reply John Colvin <john.loughran.colvin gmail.com> writes:
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.
Dec 17 2015
parent =?UTF-8?B?THXDrXM=?= Marques <luis luismarques.eu> writes:
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.
Dec 17 2015