www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - lazy void vs int delegate() as overloads - bug or illegal use of

reply "Johan =?UTF-8?B?w5ZzdGxpbmci?= <johan.f.ostling gmail.com> writes:
Hi,
I'm trying to do a version of this:

	import std.stdio;

	void main()
	{
		execute(writeln("Hello, world"));
		execute({return 5;});
	}

	void execute(int delegate() f)
	{
		writeln("f is delegate, returning ", f());
	}

	void execute(lazy void f)
	{
		writeln("f is lazy void");
		f();
	}

which causes the compiler to respond: Error: void does not have a 
default initializer.

I've narrowed it down to the fact that the function "execute" is 
overloaded - if I give them different names, it works fine.

My question is, is this a bug or is it an intentionally disabled 
way of overloading the functions?
Nov 22 2014
parent "anonymous" <anonymous example.com> writes:
On Saturday, 22 November 2014 at 15:16:42 UTC, Johan Östling
wrote:
 	void execute(lazy void f)
I think it's a bug that the compiler accepts a lazy void parameter. It errors out on a non-lazy void parameter with "cannot have parameter of type void". lazy shouldn't somehow enable void parameters.
Nov 22 2014