[Issue 16143] New: Assertion error for nested functions

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Jun 8 19:39:01 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=16143

          Issue ID: 16143
           Summary: Assertion error for nested functions
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: greensunny12 at gmail.com

For the following snippet dmd stops with:

dmd: toir.c:249: elem* getEthis(Loc, IRState*, Dsymbol*): Assertion
`thisfd->isNested() || thisfd->vthis' failed.

This probably is due to passing the nested function to another function in
`transformToInterval`. This snippet is extracted out of context - at that time
I successfully used a `struct` template to return multiple functions (tuple
didn't work).


```
struct IntervalPoint(S)
{
    S x;
    S tx;
}

IntervalPoint!S intervalPoint(alias f0, S)(S x)
{
    return IntervalPoint!S(x, f0(x));
}

auto transform(alias f0, double c)()
{
    alias t0 = (x) => x + 1;

    struct Functions2D
    {
        alias f0 = t0;
    }

    Functions2D f;
    return f;
}

auto transformToInterval(alias f0, double c, S)(S x)
{
    auto t = transform!(f0, c);
    return intervalPoint!(t.f0)(x);
}

unittest
{
    alias f0 = (x) => x + 1;
    auto t = transformToInterval!(f0, 1.0)(1.0);
}
```

--


More information about the Digitalmars-d-bugs mailing list