Odd Error Message

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Dec 15 14:20:44 PST 2014

On Mon, 15 Dec 2014 22:09:28 +0000
CraigDillabaugh via Digitalmars-d-learn
<digitalmars-d-learn at puremagic.com> wrote:

> Given the following program:
> import std.string;
> import std.stdio;
> void main()
> {	
> 	File file = File("blah.txt", "r");
> 	while( !(file.eof()) && count > 10 ) {  //line 8
> 		//
> 	}
> }
> I get the error message:
> line(8): Error: void has no value
> If I comment out the import std.string; then I get an error I 
> would expect.
> line(8): Error: undefined identifier count
> There is no 'count' symbol that I can see in std.string.
there is public import from std.algorithm inside std.string, so what
you see is about std.algorithm.count.

> Would this error message be considered a compiler bug?
i don't think so. compiler tries to instantiate std.algorithm.count and
failed doing that, so it tries to tell you about that failure. newer
compiler will tell you this:

z00.d(8): Error: void has no value
z00.d(8): Error: incompatible types for ((count(alias pred = "a == b", Range, E)(Range haystack, E needle)
  if (isInputRange!Range && !isInfinite!Range &&
  is(typeof(binaryFun!pred(haystack.front, needle)) : bool))) > (10)): 'void' and 'int'

this is slightly better, albeit still cryptic. template instantiation
error messages are of the most noisy and hard to understand ones. alas.
but poor compiler at least tries to help you. ;-)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20141216/907b5c9d/attachment.sig>

More information about the Digitalmars-d-learn mailing list