Issue 16143 - Assertion error for nested functions
Summary: Assertion error for nested functions
Status: REOPENED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P3 normal
Assignee: No Owner
URL:
Keywords: backend
Depends on:
Blocks:
 
Reported: 2016-06-09 02:39 UTC by Seb
Modified: 2022-12-17 10:37 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Seb 2016-06-09 02:39:01 UTC
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);
}
```
Comment 1 RazvanN 2022-11-09 14:49:39 UTC
I cannot reproduce this. The code compiles fine with the most recent version of master.
Comment 2 RazvanN 2022-11-09 14:50:12 UTC
Argh, forgot to add unittest. Still asserts.
Comment 3 basile-z 2022-11-09 18:03:18 UTC
Do you use an older compiler ? with dmd 2.100.2 there's an error during semantics:

> /tmp/temp_7F6C1D38FB90.d:32:32: Error: function `runnable.__unittest_L35_C1.transformToInterval!(__lambda1, 1.0, double).transformToInterval` cannot get frame pointer to `runnable.__unittest_L35_C1.transform!(__lambda1, 1.0).transform.intervalPoint!(__lambda1, double).intervalPoint`
Comment 4 RazvanN 2022-11-10 07:29:12 UTC
(In reply to Basile-z from comment #3)
> Do you use an older compiler ? with dmd 2.100.2 there's an error during
> semantics:
> 
> > /tmp/temp_7F6C1D38FB90.d:32:32: Error: function `runnable.__unittest_L35_C1.transformToInterval!(__lambda1, 1.0, double).transformToInterval` cannot get frame pointer to `runnable.__unittest_L35_C1.transform!(__lambda1, 1.0).transform.intervalPoint!(__lambda1, double).intervalPoint`

Nope, but I did not use the -unittest switch cause I did not see the unittest.

Anyway, in git master this results in an ice.