www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8714] New: Instantiate template within CTFE with same CTFE returned value

reply d-bugmail puremagic.com writes:
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



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: -------
Sep 23 2012
next sibling parent d-bugmail puremagic.com writes:
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



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: -------
Sep 24 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8714




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


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: -------
Oct 09 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
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



Fixed for D2

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 09 2012
prev sibling parent d-bugmail puremagic.com writes:
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: -------
Oct 10 2012