On Wed, Oct 16, 2013 at 10:09:50PM +0200, Daniel Davidson wrote: [...] > I reported my issue with the `chain` function to this NG and tried > to start annotating items used by chain with pure to see how far the > thread led. Honestly it was quickly clear that it led too far for me > to follow it and someone else indicated the problem had to do with > Voldermort types. If there is more I could do to "benefit us all", > beyond learning how it works and what to avoid in my own code - I > will be glad to try.
Hmm. I just did a quick-n-dirty change to Phobos, and it seems to make chain() usable with pure code. I'm not sure why the compiler didn't infer pure for it -- it should. (Or perhaps I'm missing something obvious -- I didn't run the Phobos unittest so maybe the following change breaks something.) - In the Phobos source, edit std/range.d and look for the function `auto chain(Ranges...)(Ranges rs)` (around line 2022 or thereabouts), then the struct Result inside this function. - Find the ctor for this struct (circa line 2074), and annotate it with pure. - Now the following code compiles: import std.range; auto pureFunc() pure { return chain([1,2,3], [2,3,4]); } void main() { auto r = pureFunc(); } This is just a hack, of course. The compiler *should* be able to correctly infer that the ctor is pure. So the real fix is to find out why the compiler isn't doing that. T -- Leather is waterproof. Ever see a cow with an umbrella?