Thread overview
[Issue 8714] New: Instantiate template within CTFE with same CTFE returned value
[Issue 8714] Missing error message with circular use of CTFE
Sep 25, 2012
Don
Oct 10, 2012
yebblies
Oct 10, 2012
Walter Bright
September 23, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8714

           Summary: Instantiate template within CTFE with same CTFE
                    returned value
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: jens.k.mueller@gmx.de


--- Comment #0 from jens.k.mueller@gmx.de 2012-09-23 14:08:29 PDT ---
To better integrate CTFE and templates it may be worthwhile to allow code as follows

string foo(string f)
{
   if (f == "somestring")
   {
       return "got somestring";
   }
   return bar!(foo("somestring"));
}

template bar(string s)
{
   enum bar = s;
}

Note, that the return value of foo("somestring") is "got somestring" which should be possible to pass to some template.

Code like

string foo(string f)
{
    if (f == "somestring")
    {
        return "got somestring";
    }
    return bar!(foo("somestring"))();
}

string bar(string s)()
{
    return s;
}

should compile as well.

Both fail with dmd 2.060.
The first code fails with:
test.d(7):        called from here: foo("somestring")
test.d(7):        called from here: foo("somestring")
test.d(7):        called from here: foo("somestring")
test.d(7): Error: expression foo("somestring") is not a valid template value
argument
test.d(12):        called from here: foo("somestring")
test.d(12):        called from here: foo("somestring")
test.d(7): Error: template instance test.bar!(foo("somestring")) error
instantiating

and the second with:
test.d(7):        called from here: foo("somestring")
test.d(7):        called from here: foo("somestring")
test.d(7):        called from here: foo("somestring")
test.d(7): Error: expression foo("somestring") is not a valid template value
argument
test.d(7): Error: template instance test.bar!(foo("somestring")) error
instantiating

If code like above should stay invalid the compiler diagnostics should be improved. I.e. recursive dependency on foo when analyzing foo in CTFE.

See also the discussion on the list http://forum.dlang.org/thread/mailman.148.1348176167.5162.digitalmars-d@puremagic.com http://forum.dlang.org/thread/20120920212236.GD3056@minet.uni-jena.de

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 25, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8714


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |CTFE, diagnostic, pull
                 CC|                            |clugdbug@yahoo.com.au
            Summary|Instantiate template within |Missing error message with
                   |CTFE with same CTFE         |circular use of CTFE
                   |returned value              |
           Severity|enhancement                 |normal


--- Comment #1 from Don <clugdbug@yahoo.com.au> 2012-09-24 23:39:16 PDT ---
Original title: Instantiate template within CTFE with same CTFE returned value

The 'enhancement request' part of this bug is the same as bug 8713. Changing this to a diagnostic bug.

https://github.com/D-Programming-Language/dmd/pull/1141

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 10, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8714



--- Comment #2 from github-bugzilla@puremagic.com 2012-10-09 22:33:00 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/4eb179d96c4b3402250a707e29ca00ca982cd431 Fix issue 8714 Missing error message with circular use of CTFE

The error message was missing, and the supplementary error was also spuriously repeated.

https://github.com/D-Programming-Language/dmd/commit/649ad799371e282391813ba9126f5f63f4223656 Merge pull request #1141 from donc/ctfe8714recursive_semantic

Fix issue 8714 Missing error message with circular use of CTFE

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 10, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8714


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies@gmail.com
            Version|D2                          |D1


--- Comment #3 from yebblies <yebblies@gmail.com> 2012-10-10 16:34:37 EST ---
Fixed for D2

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 10, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8714


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
            Version|D1                          |D1 & D2
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------