[Issue 3339] New: template "is not evaluatable at compile time" error inconsistencies

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Sep 22 01:33:37 PDT 2009


http://d.puremagic.com/issues/show_bug.cgi?id=3339

           Summary: template "is not evaluatable at compile time" error
                    inconsistencies
           Product: D
           Version: 2.032
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: chadjoan at gmail.com


--- Comment #0 from Chad Joan <chadjoan at gmail.com> 2009-09-22 01:33:36 PDT ---
Version 1 of the program:
---------------------------------------
pure string wham(string str)
{
    return str;
}

template ouch(string val)
{
    mixin(`const bool ouch = `~wham(val)~`;`);
}

static assert( ouch!("true") );
static assert( !ouch!("false") );

void main(){}
---------------------------------------
This will compile just fine.  

I'm actually not sure if it should or not.

By moving the wham function into the ouch template, the code will no longer
compile; complaining about not being able to evaluate ouch at compile time. 
The changes make it look like so:
---------------------------------------
template ouch(string val)
{
    pure string wham(string str)
    {
        return str;
    }

    mixin(`const bool ouch = `~wham(val)~`;`);
}

static assert( ouch!("true") );
static assert( !ouch!("false") );

void main(){}
---------------------------------------
main2.d(11): Error: static assert  (ouch!("true")) is not evaluatable at
compile time


Another way to get the error is to store the result of wham into a constant and
try to use it:
---------------------------------------
pure string wham(string str)
{
    return str;
}

template ouch(string val)
{
    const string str = wham(val);
    mixin(`const bool ouch = `~str~`;`);
    // Same goes for `enum str = wham(val);`
}

static assert( ouch!("true") );
static assert( !ouch!("false") );

void main(){}
---------------------------------------
main3.d(13): Error: static assert  (ouch!("true")) is not evaluatable at
compile time

Again, I'm not actually sure whether these examples should compile or not. 
However, they should all be equivalent, yet one case will compile and the other
ones will not.

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


More information about the Digitalmars-d-bugs mailing list