Thread overview
[Issue 14694] Functions nested within functions need their body in the generated .di file
Jun 17, 2015
Walter Bright
Jun 17, 2015
Vladimir Panteleev
Oct 06, 2022
RazvanN
Oct 06, 2022
RazvanN
Oct 10, 2022
RazvanN
June 12, 2015
https://issues.dlang.org/show_bug.cgi?id=14694

Andrei Alexandrescu <andrei@erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Blocks|                            |14680

--
June 17, 2015
https://issues.dlang.org/show_bug.cgi?id=14694

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com

--- Comment #1 from Walter Bright <bugzilla@digitalmars.com> ---
(In reply to Andrei Alexandrescu from comment #0)
> Obviously that's not going to work for more than one reason :o).

Instead of asking people to carefully examine moderately complex code looking for a mistake, and wondering how many and which you mean, please be explicit.

--
June 17, 2015
https://issues.dlang.org/show_bug.cgi?id=14694

Vladimir Panteleev <thecybershadow@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |thecybershadow@gmail.com

--- Comment #2 from Vladimir Panteleev <thecybershadow@gmail.com> ---
(In reply to Walter Bright from comment #1)
> Instead of asking people to carefully examine moderately complex code looking for a mistake, and wondering how many and which you mean, please be explicit.

Is it not obvious?

Here:

(In reply to Andrei Alexandrescu from comment #0)
> Obvious in retrospect. Repro picked from std.array:
> 
> inout(T)[] overlap(T)(inout(T)[] r1, inout(T)[] r2) @trusted pure nothrow
> {
>     alias U = inout(T);
>     static U* max(U* a, U* b) nothrow { return a > b ? a : b; }
>     static U* min(U* a, U* b) nothrow { return a < b ? a : b; }

These two nested functions (min and max) have a body.

> 
>     auto b = max(r1.ptr, r2.ptr);
>     auto e = min(r1.ptr + r1.length, r2.ptr + r2.length);
>     return b < e ? b[0 .. e - b] : null;
> }
> 
> After .di generation:
> 
> pure nothrow @trusted inout(T)[] overlap(T)(inout(T)[] r1, inout(T)[] r2)
> {
>         alias U = inout(T);
>         static nothrow U* max(U* a, U* b);
>         static nothrow U* min(U* a, U* b);

Here, the bodies of the nested functions was stripped.

>         auto b = max(r1.ptr, r2.ptr);
>         auto e = min(r1.ptr + r1.length, r2.ptr + r2.length);
>         return b < e ? b[0..e - b] : null;
> }
> 
> Obviously that's not going to work for more than one reason :o).

--
June 17, 2015
https://issues.dlang.org/show_bug.cgi?id=14694

--- Comment #3 from Andrei Alexandrescu <andrei@erdani.com> ---
(In reply to Walter Bright from comment #1)
> (In reply to Andrei Alexandrescu from comment #0)
> > Obviously that's not going to work for more than one reason :o).
> 
> Instead of asking people to carefully examine moderately complex code looking for a mistake, and wondering how many and which you mean, please be explicit.

Well it won't work because it's impossible to define a nested function outside the function it's in. So the definition must go there.

--
October 06, 2022
https://issues.dlang.org/show_bug.cgi?id=14694

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |razvan.nitu1305@gmail.com
           Severity|enhancement                 |normal

--
October 06, 2022
https://issues.dlang.org/show_bug.cgi?id=14694

--- Comment #4 from RazvanN <razvan.nitu1305@gmail.com> ---
PR: https://github.com/dlang/dmd/pull/14529

--
October 10, 2022
https://issues.dlang.org/show_bug.cgi?id=14694

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--