Bug 5250 – Pure std.typecons.Tuple

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-11-21T16:12:00Z
Last change time
2011-07-14T17:30:20Z
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2010-11-21T16:12:31Z
This D2 program seems to show that a strongly pure function can't generate and return a std.typecons.Tuple, but I'd like it, if possible: import std.typecons: Tuple; pure Tuple!int foo() { return Tuple!int(0); } void main() { assert(foo()[0] == 0); } dmd 2.050 shows the error: test.d(3): Error: pure function 'foo' cannot call impure function 'this'
Comment #1 by bearophile_hugs — 2010-11-21T16:21:53Z
The same is true for "nothrow" attribute: import std.typecons: Tuple; pure nothrow Tuple!int foo() { return Tuple!int(0); } void main() { assert(foo()[0] == 0); }
Comment #2 by bearophile_hugs — 2011-07-14T17:30:20Z
Yay, fixed in DMD 2.054. Pure Tuples are useful in functional-style programming.