Thread overview
[Issue 13204] recursive alias declaration
Jul 25, 2014
Jonathan M Davis
Jul 25, 2014
Trass3r
Jul 25, 2014
Jonathan M Davis
Jul 28, 2014
Kenji Hara
Jul 28, 2014
Kenji Hara
Jul 28, 2014
Trass3r
Sep 14, 2014
Kenji Hara
Jul 03, 2017
Vladimir Panteleev
July 25, 2014
https://issues.dlang.org/show_bug.cgi?id=13204

Jonathan M Davis <jmdavisProg@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |jmdavisProg@gmx.com
         Resolution|---                         |INVALID

--- Comment #1 from Jonathan M Davis <jmdavisProg@gmx.com> ---
Okay. Think this through. When you declare

alias A1 = ABase!1; // L6

it now has to instantiate ABase with 1. When it does that it has to define

alias whatever = Foo;

Foo is then an alias to A1, which is an alias to ABase!1. So, to determine what Foo is, it has to instantiate ABase!1, which it's already in the middle of doing. It's clearly recursive and isn't going to end. You always have to be _very_ careful when attempting to instantiate a template within itself. You need template constraints or static ifs to fix the problem. So, in this case, you'd probably need to do something like this (untested).

struct ABase(uint v)
{
    static if(v == 1)
        alias whatever = ABase;
    else
        alias whatever = Foo;
}

And as to an improved error message, I don't know what else would help you. It told you the line that where the problem was, and the definition of Foo clearly is attempting to instantiate the template that the error was in. If you can suggest an error message that would be more helpful, that would be great, but as far as I can tell, the compiler is telling you exactly what's wrong.

--
July 25, 2014
https://issues.dlang.org/show_bug.cgi?id=13204

--- Comment #2 from Trass3r <mrmocool@gmx.de> ---
Of course the recursion is obvious in this reduced form! (thanks to DustMite)
But in the real code with more aliases etc. it's not and you only get the start
of the circle.
So it would be nice if at least one more node was given if possible, i.e. the
whatever alias.

--
July 25, 2014
https://issues.dlang.org/show_bug.cgi?id=13204

--- Comment #3 from Jonathan M Davis <jmdavisProg@gmx.com> ---
Well, as I said if you can come up with what a better error message would look like, please suggest it and open it as an enhancement. I'm not at all against the idea. I just don't what would actually be better, and as someone who had to deal with the problem and found the current message to be lacking, you'll have a better idea of what would have helped you than I would.

--
July 28, 2014
https://issues.dlang.org/show_bug.cgi?id=13204

Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |---

--- Comment #4 from Kenji Hara <k.hara.pg@gmail.com> ---
I think this is fixable issue.

(In reply to Jonathan M Davis from comment #1)
> Okay. Think this through. When you declare
> 
> alias A1 = ABase!1; // L6

In this first timing, ABase!1 is not yet instantiated, so its eponymous member is yet unknown. But,

> it now has to instantiate ABase with 1. When it does that it has to define
> 
> alias whatever = Foo;
> 
> Foo is then an alias to A1, which is an alias to ABase!1. So, to determine what Foo is, it has to instantiate ABase!1, which it's already in the middle of doing.

In this second timing, compiler can recognize an aliasing from ABase!1 to the instantiated struct type ABase!1.ABase, because the eponymous template member can be lexically known, even though the semantic analysis of ABase!1 is not yet completed. So compiler can make the alias A1 to the struct ABase!1.ABase.

--
July 28, 2014
https://issues.dlang.org/show_bug.cgi?id=13204

Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #5 from Kenji Hara <k.hara.pg@gmail.com> ---
https://github.com/D-Programming-Language/dmd/pull/3822

--
July 28, 2014
https://issues.dlang.org/show_bug.cgi?id=13204

--- Comment #6 from Trass3r <mrmocool@gmx.de> ---
Thanks Kenji!

--
August 15, 2014
https://issues.dlang.org/show_bug.cgi?id=13204

--- Comment #7 from github-bugzilla@puremagic.com ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/44fe178acefdf45f56d42bbad582c42f412c78e1 fix Issue 13204 - recursive alias declaration

https://github.com/D-Programming-Language/dmd/commit/83e0a9919cc07f6de2b76111878ef1905fbcaf3f Merge pull request #3822 from 9rnsr/fix13204

Issue 13204 - recursive alias declaration

--
August 29, 2014
https://issues.dlang.org/show_bug.cgi?id=13204

--- Comment #8 from github-bugzilla@puremagic.com ---
Commit pushed to 2.066 at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/5fed9e61acaca03822dd871372ebf6cfe19df989 Merge pull request #3822 from 9rnsr/fix13204

Issue 13204 - recursive alias declaration

--
September 14, 2014
https://issues.dlang.org/show_bug.cgi?id=13204

Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich@gmail.com

--- Comment #9 from Kenji Hara <k.hara.pg@gmail.com> ---
*** Issue 8462 has been marked as a duplicate of this issue. ***

--
July 03, 2017
https://issues.dlang.org/show_bug.cgi?id=13204

Vladimir Panteleev <dlang-bugzilla@thecybershadow.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rswhite4@googlemail.com

--- Comment #10 from Vladimir Panteleev <dlang-bugzilla@thecybershadow.net> ---
*** Issue 10705 has been marked as a duplicate of this issue. ***

--