Bug 8833 – Odd error with expression tuples

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-10-16T20:12:00Z
Last change time
2013-04-06T16:13:06Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
andrej.mitrovich

Comments

Comment #0 by andrej.mitrovich — 2012-10-16T20:12:56Z
import std.typetuple; void func(alias arg)() { } void main() { int x, y; alias TypeTuple!( func!(x), func!(y), ) Map; } test.d(9): Error: template instance TypeTuple!(func,func) TypeTuple!(func,func) is nested in both func!(x) and func!(y) But this works fine (notice 'y' isn't passed here): void main() { int x, y; alias TypeTuple!( func!(x), func!(x), ) Map; } This was while trying to implement an interesting question on SO: http://stackoverflow.com/questions/12888263/mapping-variadic-template-arguments-in-d That solution is partially implementable by constructing function call expressions, however I can never get around this strange bug.
Comment #1 by andrej.mitrovich — 2012-10-16T20:26:04Z
Btw if you want to see some interesting code: import std.stdio; import std.typetuple; int Delay(alias Call, alias arg)() { return Call(arg); } template Map(alias Call, args...) { alias TypeTuple!( Delay!(Call, args[0]), //~ Delay!(Call, args[1]), // can't due to error 2 * 10 // pretend we could ) Map; } int fun(int arg) { return arg * 10; } void foo(Args...)(Args args) { print( Map!(fun, args) ); } void print(int res1, int res2) { writefln("%s %s", res1, res2); // writes 10 20 } void main() { int x = 1; int y = 2; foo(x, y); } Fun or what?
Comment #2 by andrej.mitrovich — 2012-10-16T20:27:16Z
(In reply to comment #1) > int Delay(alias Call, alias arg)() { return Call(arg); } Btw although 'auto' won't work here (forward reference error) we can easily use ReturnType!Call in the return type.
Comment #3 by k.hara.pg — 2013-04-06T06:38:35Z
Comment #4 by github-bugzilla — 2013-04-06T16:12:37Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/2d9929c13637e111c16f174da1735a0bf31e0f04 fix Issue 8833 - Odd error with expression tuples https://github.com/D-Programming-Language/dmd/commit/5036f158eb45d35c59db5b8c85aef152cd38dee4 Merge pull request #1852 from 9rnsr/fix8833 Issue 8833 - Odd error with expression tuples