D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1396 - lazy void tuple breaks
Summary: lazy void tuple breaks
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2007-08-02 14:57 UTC by FeepingCreature
Modified: 2015-06-09 01:31 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description FeepingCreature 2007-08-02 14:57:45 UTC
import std.stdio;
template tuple(T...) { alias T tuple; }
void test(lazy tuple!(void, void) a) { a[0](); a[1](); }
void main() { test(writefln("Hello"), writefln("World")); }

Expected: "Hello\nWorld"
Resulted: Error: cannot have parameter of type void.
Observed: Seems as if the lazy isn't being applied to all the tuple members as it should be.

 --downs
Comment 1 FeepingCreature 2007-08-02 15:02:57 UTC
Added comment: Seems to happen whenever the tuple contains at least one void, for every void in the tuple.
Comment 2 Christopher Nicholson-Sauls 2007-08-02 17:12:17 UTC
(In reply to comment #0)
> import std.stdio;
> template tuple(T...) { alias T tuple; }
> void test(lazy tuple!(void, void) a) { a[0](); a[1](); }
> void main() { test(writefln("Hello"), writefln("World")); }
> 
> Expected: "Hello\nWorld"
> Resulted: Error: cannot have parameter of type void.
> Observed: Seems as if the lazy isn't being applied to all the tuple members as
> it should be.
> 
>  --downs
> 

Since 'lazy void' is really shorthand for 'void delegate()' I wouldn't actually have expected 'lazy' to work in this way anyhow...  Although it could indeed be useful.  Try running it with 'tuple!(lazy void, lazy void) a' and it should work.

I consider this an enhancement request, or clarification request, rather than a bug.  (It'd be a nice enhancement, though.)
Comment 3 FeepingCreature 2007-08-03 21:52:31 UTC
(In reply to comment #2)
> Since 'lazy void' is really shorthand for 'void delegate()' I wouldn't actually
> have expected 'lazy' to work in this way anyhow...  

Works with int.

gentoo-pc ~/d $ cat bug.d && echo ---- && gdc bug.d -o bug && ./bug
import std.stdio;
template tuple(T...) { alias T tuple; }
void test(lazy tuple!(int, int) a) { writefln("Eval now"); writefln(a[0], "-", a[1]); }
void main() { test({writefln("Hello"); return 1; }(), {writefln("World"); return 2; }()); }
----
Eval now
World
Hello
1-2

> Although it could indeed be
> useful.  Try running it with 'tuple!(lazy void, lazy void) a' and it should
> work.
> 
> I consider this an enhancement request, or clarification request, rather than a
> bug.  (It'd be a nice enhancement, though.)
> 

import std.stdio;
template tuple(T...) { alias T tuple; }
void test(tuple!(lazy void, lazy void) a) { a[0](); a[1](); }
void main() { test(writefln("Hello"), writefln("World")); }

gentoo-pc ~/d $ gdc bug.d -o bug
bug.d:3: expression expected, not 'lazy'

Thanks for the suggestion, though.
 --downs
Comment 4 Don 2010-01-15 05:28:50 UTC
Fixed DMD1.054.