D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 13935 - Problem with std.algorithm.cartesianProduct(map, map)
Summary: Problem with std.algorithm.cartesianProduct(map, map)
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86 Windows
: P1 normal
Assignee: No Owner
URL:
Keywords: pull, rejects-valid
Depends on:
Blocks:
 
Reported: 2015-01-05 04:49 UTC by bearophile_hugs
Modified: 2015-02-18 03:41 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 bearophile_hugs 2015-01-05 04:49:07 UTC
void main() {
    import std.algorithm: map, cartesianProduct;
    auto seq = [1, 2].map!(x => x);
    foreach (pair; cartesianProduct(seq, seq)) {}
}


dmd 2.067alpha gives:

...\dmd2\src\phobos\std\algorithm.d(14489,20): Error: function std.algorithm.cartesianProduct!(MapResult!(__lambda1, Result), MapResult!(__lambda1, Result)).cartesianProduct.Result.save cannot get frame pointer to main
...\dmd2\src\phobos\std\algorithm.d(14489,20): Error: function std.algorithm.cartesianProduct!(MapResult!(__lambda1, Result), MapResult!(__lambda1, Result)).cartesianProduct.Result.save cannot get frame pointer to main
...\dmd2\src\phobos\std\algorithm.d(14489,20): Error: function std.algorithm.cartesianProduct!(MapResult!(__lambda1, Result), MapResult!(__lambda1, Result)).cartesianProduct.Result.save cannot get frame pointer to main
...\dmd2\src\phobos\std\algorithm.d(14489,20): Error: function std.algorithm.cartesianProduct!(MapResult!(__lambda1, Result), MapResult!(__lambda1, Result)).cartesianProduct.Result.save cannot get frame pointer to main


Taking a look at the std.algorithm.cartesianProduct implementation:


auto cartesianProduct(RR...)(RR ranges)
    if (ranges.length >= 2 &&
        allSatisfy!(isForwardRange, RR) &&
        !anySatisfy!(isInfinite, RR))
{
...
    static struct Result
    {
...
        @property Result save()
        {
            Result copy; // Error message here *******
            foreach (i, r; ranges)
            {
                copy.ranges[i] = r.save;
                copy.current[i] = current[i].save;
            }
            copy.empty = this.empty;
            return copy;
        }
    }
...

-----------------------
Comment 2 github-bugzilla 2015-01-10 07:44:27 UTC
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/51e390d0bbc764e2866b1fb4c1c3fc532f6f7537
Issue 13935: do not assume range can be default-initialized.

When the incoming range is parametrized on something that requires a
frame pointer, we cannot declare default-initialized instances of its
type; to work around this in .save, just make a copy of `this` and then
kick it into shape before returning it.

https://github.com/D-Programming-Language/phobos/commit/9a655323a16585ba9dc9b3ae547d51123a4f4b9d
Merge pull request #2860 from quickfur/issue13935

Issue 13935: do not assume range can be default-initialized.