Thread overview
[Issue 19674] multiple local template function with same name don't work
Feb 13, 2019
Alex
Feb 13, 2019
Iain Buclaw
Feb 13, 2019
Iain Buclaw
Feb 21, 2019
RazvanN
Feb 21, 2019
Alex
Jul 19, 2021
Mathias LANG
February 13, 2019
https://issues.dlang.org/show_bug.cgi?id=19674

--- Comment #1 from Alex <alex@sunopti.com> ---
Found in :
gdc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516
Replicated in dlang.org "your code here"

--
February 13, 2019
https://issues.dlang.org/show_bug.cgi?id=19674

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ibuclaw@gdcproject.org

--- Comment #2 from Iain Buclaw <ibuclaw@gdcproject.org> ---
A frame gets created in main() with both 'a' vars as fields.

(gdb) pt this
type = struct FRAME.D main {
    int [] a;
    int [] a;
} * const

(gdb) p *this
$1 = {a = {3, 3}, a = 0x0}


However, looks like only one add() is sent to the code generation phase to be
emitted.

In this case, the first add(), which only appends to the first field in the
frame.

Two functions should be generated, though need to avoid the pitfall of conflicting symbols.

--
February 13, 2019
https://issues.dlang.org/show_bug.cgi?id=19674

--- Comment #3 from Iain Buclaw <ibuclaw@gdcproject.org> ---
Or, granted that this is an error.

void main()
{
    import core.stdc.stdio;
    {
        static int[] a;
        a ~= 3;
        if (a.length)
            printf("[%d]\n",a[0]);
        else
            printf("[]\n");
    }
    {
        static int[] a;
        a ~= 3;
        if (a.length)
            printf("[%d]\n",a[0]);
        else
            printf("[]\n");
    }
}

Reject the given example for functions as well.

--
February 21, 2019
https://issues.dlang.org/show_bug.cgi?id=19674

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

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

--- Comment #4 from RazvanN <razvan.nitu1305@gmail.com> ---
(In reply to Iain Buclaw from comment #3)
> Or, granted that this is an error.
> 
> void main()
> {
>     import core.stdc.stdio;
>     {
>         static int[] a;
>         a ~= 3;
>         if (a.length)
>             printf("[%d]\n",a[0]);
>         else
>             printf("[]\n");
>     }
>     {
>         static int[] a;
>         a ~= 3;
>         if (a.length)
>             printf("[%d]\n",a[0]);
>         else
>             printf("[]\n");
>     }
> }
> 
> Reject the given example for functions as well.

(In reply to Iain Buclaw from comment #2)
> A frame gets created in main() with both 'a' vars as fields.
> 
> (gdb) pt this
> type = struct FRAME.D main {
>     int [] a;
>     int [] a;
> } * const
> 
> (gdb) p *this
> $1 = {a = {3, 3}, a = 0x0}
> 
> 
> However, looks like only one add() is sent to the code generation phase to
> be emitted.
> 
> In this case, the first add(), which only appends to the first field in the
> frame.
> 
> Two functions should be generated, though need to avoid the pitfall of conflicting symbols.

I think that the guideline should be what happens when the functions are not templated:

void main()
{
    import std.stdio;
        {
                auto a = new int[0];
                void add(int x)
                {
                        a ~= x;
                }
                add(3);
                writefln("%s",a);       //should be [3] and is
        }
        {
                auto a = new int[0];
                void add(int x)
                {
                        a ~= x;
                }
                add(3);
                writefln("%s",a);       //should be [3] but isn't
        }
}

This yields:

Error: declaration onlineapp.main.add is already defined in another scope in main at line 6

This should be the result for templated functions also.

--
February 21, 2019
https://issues.dlang.org/show_bug.cgi?id=19674

--- Comment #5 from Alex <alex@sunopti.com> ---
I think the nested function should not be able to see each other from those
scopes. They should not conflict or be able to be called from the other scope
regardless of whether template or not. This way the same rules apply as with
variables.
The compiler conflict error is preferable to current misbehaviour.

--
July 19, 2021
https://issues.dlang.org/show_bug.cgi?id=19674

Mathias LANG <pro.mathias.lang@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |pro.mathias.lang@gmail.com
         Resolution|---                         |DUPLICATE

--- Comment #6 from Mathias LANG <pro.mathias.lang@gmail.com> ---
Fixed in v2.096.1 as this is a duplicate of issue 14831.

*** This issue has been marked as a duplicate of issue 14831 ***

--