Thread overview
Odd Error Message
Dec 15, 2014
CraigDillabaugh
Dec 15, 2014
bearophile
Dec 15, 2014
ketmar
Dec 16, 2014
CraigDillabaugh
December 15, 2014
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)

December 15, 2014
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
December 15, 2014
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. ;-)


December 16, 2014
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.