www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16143] New: Assertion error for nested functions

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 puremagic.com
          Reporter: greensunny12 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);
}
```

--
Jun 08 2016