Bug 4273 – Error: functions cannot return a tuple

Status
RESOLVED
Resolution
WONTFIX
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Mac OS X
Creation time
2010-06-04T16:24:00Z
Last change time
2015-06-09T01:27:38Z
Assigned to
nobody
Creator
sean

Comments

Comment #0 by sean — 2010-06-04T16:24:41Z
If line A is changed to "auto x = foo(1,2);" then the code compiles without incident. This should compile with one parameter as well. import std.typecons; template fooRet(T...) { static if( T.length == 1 ) alias T fooRet; else alias Tuple!(T) fooRet; } fooRet!(T) foo(T...)(T vals) { Tuple!(T) ret; static if( T.length == 1 ) return ret.field[0]; else return ret; } void main() { auto x = foo(1); // A }
Comment #1 by bearophile_hugs — 2010-06-04T16:55:10Z
I don't understand the purpose of your code, but I think the problems are in your code. Maybe in fooRet you meant to use: alias T[0] fooRet; You can also use: auto foo(T...)(T vals)
Comment #2 by bugzilla — 2010-06-04T17:16:41Z
"Fixing" this would require conflating a Tuple!(T) with T. I think this would be a mistake.
Comment #3 by sean — 2010-06-04T18:21:00Z
You're right, it was a mistake in my code. Sorry.