www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - [Solved] Confusing error message

reply Wulfklaue <wulfklaue wulfklaue.com> writes:
Some of the dmd error messages need some tweaking.

 import std.datetime;

 auto t = Clock.currStdTime;
 writeln(to!string(t));
Result in:
 Error: template core.time.to cannot deduce function from 
 argument types !(string)(long), candidates are:
 C:\D\dmd2\windows\bin\..\..\src\druntime\import\core\time.d(1709):       
core.time.to(string units, T, D)(D td) if (is(_Unqual!D == TickDuration) &&
(units == "seconds" || units == "msecs" || units == "usecs" || units ==
"hnsecs" || units == "nsecs"))
 import std.datetime;
 import std.conv;

 auto t = Clock.currStdTime;
 writeln(to!string(t));
Solves the issue but its strange that there is no error message indicating that to! needs the std.conv included. Technically one can argue that the original message mean that but its very, very unclear.
Jun 07 2017
next sibling parent bachmeier <no spam.net> writes:
On Wednesday, 7 June 2017 at 13:27:05 UTC, Wulfklaue wrote:
 Some of the dmd error messages need some tweaking.

 import std.datetime;

 auto t = Clock.currStdTime;
 writeln(to!string(t));
Result in:
 Error: template core.time.to cannot deduce function from 
 argument types !(string)(long), candidates are:
 C:\D\dmd2\windows\bin\..\..\src\druntime\import\core\time.d(1709):       
core.time.to(string units, T, D)(D td) if (is(_Unqual!D == TickDuration) &&
(units == "seconds" || units == "msecs" || units == "usecs" || units ==
"hnsecs" || units == "nsecs"))
 import std.datetime;
 import std.conv;

 auto t = Clock.currStdTime;
 writeln(to!string(t));
Solves the issue but its strange that there is no error message indicating that to! needs the std.conv included. Technically one can argue that the original message mean that but its very, very unclear.
Best to report it and make a suggestion of what it should say. Nothing will happen if you post here. https://issues.dlang.org/
Jun 07 2017
prev sibling parent reply drug <drug2004 bk.ru> writes:
07.06.2017 16:27, Wulfklaue пишет:
 Some of the dmd error messages need some tweaking.
 
 import std.datetime;

 auto t = Clock.currStdTime;
 writeln(to!string(t));
Result in:
 Error: template core.time.to cannot deduce function from argument 
 types !(string)(long), candidates are:
 C:\D\dmd2\windows\bin\..\..\src\druntime\import\core\time.d(1709):        
 core.time.to(string units, T, D)(D td) if (is(_Unqual!D == 
 TickDuration) && (units == "seconds" || units == "msecs" || units == 
 "usecs" || units == "hnsecs" || units == "nsecs"))
 import std.datetime;
 import std.conv;

 auto t = Clock.currStdTime;
 writeln(to!string(t));
Solves the issue but its strange that there is no error message indicating that to! needs the std.conv included. Technically one can argue that the original message mean that but its very, very unclear.
Error is right indicating that _available_ function `core.time.to` can not deduce from given types. It's impossible for compiler to know that you want use `std.conv.to` symbol. In other words compiler says that it knows only one function `to` and this function are in `core.time.` module. And this function can not be called with given args. I prefer to use selective imports and in this case compiler would say it doesn't know function `to`. For me it's a good message.
Jun 07 2017
parent reply bachmeier <no spam.net> writes:
On Wednesday, 7 June 2017 at 14:58:26 UTC, drug wrote:
 07.06.2017 16:27, Wulfklaue пишет:
 Some of the dmd error messages need some tweaking.
 
 import std.datetime;

 auto t = Clock.currStdTime;
 writeln(to!string(t));
Result in:
 Error: template core.time.to cannot deduce function from 
 argument types !(string)(long), candidates are:
 C:\D\dmd2\windows\bin\..\..\src\druntime\import\core\time.d(1709):       
core.time.to(string units, T, D)(D td) if (is(_Unqual!D == TickDuration) &&
(units == "seconds" || units == "msecs" || units == "usecs" || units ==
"hnsecs" || units == "nsecs"))
[...]
 For me it's a good message.
Messages like this were an annoyance when I started out. If you don't import std.stdio, you get the error message Error: 'writeln' is not defined, perhaps you need to import std.stdio; ? That's a very helpful error message if you're new to D, and especially helpful if you're new to programming. This particular error is likely a common one, and adding "perhaps you need to import std.conv" would help a lot. Even a generic "perhaps you forgot an import statement" would tell new users what the error might be. Making it worse is that it says core.time.to but there was no import of core.time.
Jun 07 2017
parent reply drug <drug2004 bk.ru> writes:
07.06.2017 21:07, bachmeier пишет:
 On Wednesday, 7 June 2017 at 14:58:26 UTC, drug wrote:
 
 For me it's a good message.
Messages like this were an annoyance when I started out. If you don't import std.stdio, you get the error message Error: 'writeln' is not defined, perhaps you need to import std.stdio; ? That's a very helpful error message if you're new to D, and especially helpful if you're new to programming. This particular error is likely a common one, and adding "perhaps you need to import std.conv" would help a lot. Even a generic "perhaps you forgot an import statement" would tell new users what the error might be. Making it worse is that it says core.time.to but there was no import of core.time.
How do compiler know that you want use `std.conv.to` instead of _already imported_ `core.time.to`? In general it's impossible. There is no way for compiler to guess that you want some other symbol from out there. What if you've imported `std.conv.to` but want to use `core.time.to` - what should compiler do in this case? What about `writeln` - it's too different.
Jun 07 2017
parent reply bachmeier <no spam.net> writes:
On Wednesday, 7 June 2017 at 19:02:59 UTC, drug wrote:

 How do compiler know that you want use `std.conv.to` instead of 
 _already imported_ `core.time.to`? In general it's impossible. 
 There is no way for compiler to guess that you want some other 
 symbol from out there. What if you've imported `std.conv.to` 
 but want to use `core.time.to` - what should compiler do in 
 this case?
 What about `writeln` - it's too different.
The differences with writeln are not really relevant if we're talking about error messages. The compiler knows someone is calling function `to`. If you've already imported std.conv.to, then there's no reason to print anything. In any event, I made a second suggestion that would always work. If it can't find a match, it asks if you're missing an import statement, as a way to provide the new D programmer a hint of what to look for.
Jun 07 2017
parent reply drug <drug2004 bk.ru> writes:
07.06.2017 22:40, bachmeier пишет:
 On Wednesday, 7 June 2017 at 19:02:59 UTC, drug wrote:
 
 How do compiler know that you want use `std.conv.to` instead of 
 _already imported_ `core.time.to`? In general it's impossible. There 
 is no way for compiler to guess that you want some other symbol from 
 out there. What if you've imported `std.conv.to` but want to use 
 `core.time.to` - what should compiler do in this case?
 What about `writeln` - it's too different.
The differences with writeln are not really relevant if we're talking about error messages. The compiler knows someone is calling function `to`. If you've already imported std.conv.to, then there's no reason to print anything.
Why? I have imported `std.conv.to`, but want `core.time.to` (inverted case), what should compiler do to be a good one for newcomers?
 
 In any event, I made a second suggestion that would always work. If it 
 can't find a match, it asks if you're missing an import statement, as a 
 way to provide the new D programmer a hint of what to look for.
That's a good point.
Jun 07 2017
parent reply "H. S. Teoh via Digitalmars-d-learn" <digitalmars-d-learn puremagic.com> writes:
On Wed, Jun 07, 2017 at 11:16:14PM +0300, drug via Digitalmars-d-learn wrote:
 07.06.2017 22:40, bachmeier пишет:
[...]
 In any event, I made a second suggestion that would always work. If
 it can't find a match, it asks if you're missing an import
 statement, as a way to provide the new D programmer a hint of what
 to look for.
That's a good point.
Does that mean that every time you make a typo or pass wrong arguments to a template function, the compiler will ask if you're missing an import? T -- Being able to learn is a great learning; being able to unlearn is a greater learning.
Jun 07 2017
parent bachmeier <no spam.net> writes:
On Wednesday, 7 June 2017 at 21:13:37 UTC, H. S. Teoh wrote:
 On Wed, Jun 07, 2017 at 11:16:14PM +0300, drug via 
 Digitalmars-d-learn wrote:
 07.06.2017 22:40, bachmeier пишет:
[...]
 In any event, I made a second suggestion that would always 
 work. If it can't find a match, it asks if you're missing an 
 import statement, as a way to provide the new D programmer a 
 hint of what to look for.
That's a good point.
Does that mean that every time you make a typo or pass wrong arguments to a template function, the compiler will ask if you're missing an import? T
Is there a reason to not do that? The lengthy error messages don't mean much to new D programmers now. Adding a few additional words to help them shouldn't be a problem.
Jun 07 2017