www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Odd Error Message

reply "CraigDillabaugh" <craig.dillabaugh gmail.com> writes:
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.

Would this error message be considered a compiler bug?

DMD32 D Compiler v2.066.1 (on Windows 7)
Dec 15 2014
next sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
CraigDillabaugh:

 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
The next error message is: test.d(8,29): 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' So it's referring to std.algorithm.count, that probably is imported by one of the other two imports. Bye, bearophile
Dec 15 2014
prev sibling parent reply ketmar via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
On Mon, 15 Dec 2014 22:09:28 +0000
CraigDillabaugh via Digitalmars-d-learn
<digitalmars-d-learn puremagic.com> wrote:

 Given the following program:
=20
 import std.string;
 import std.stdio;
=20
 void main()
 {=09
 	File file =3D File("blah.txt", "r");
 =09
 	while( !(file.eof()) && count > 10 ) {  //line 8
 		//
 	}
 }
=20
 I get the error message:
=20
 line(8): Error: void has no value
=20
 If I comment out the import std.string; then I get an error I=20
 would expect.
=20
 line(8): Error: undefined identifier count
=20
 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 =3D "a =3D=3D b"= , Range, E)(Range haystack, E needle) if (isInputRange!Range && !isInfinite!Range && is(typeof(binaryFun!pred(haystack.front, needle)) : bool))) > (10)): 'voi= d' 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. ;-)
Dec 15 2014
parent "CraigDillabaugh" <craig.dillabaugh gmail.com> writes:
On Monday, 15 December 2014 at 22:20:53 UTC, ketmar via 
Digitalmars-d-learn wrote:
 On Mon, 15 Dec 2014 22:09:28 +0000
 CraigDillabaugh via Digitalmars-d-learn
 <digitalmars-d-learn 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. ;-)
Thanks Ketmar and Bearophile.
Dec 16 2014