www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14018] New: Treat CTFE-able functions as pure in CTFE-only


          Issue ID: 14018
           Summary: Treat CTFE-able functions as pure in CTFE-only
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: verylonglogin.reg gmail.com

If a function is executed during CTFE it's effectively `pure` for given
parameters. This enhancement proposes to treat a function as a `pure` one in
such contexts.

E.g. it will allow implicit conversion of a function result to `immutable`:
int g = 0;
int[] f(int i)
    return new int[1];

static immutable s1 = f(0); // OK

void main()
    static immutable s2 = f(0); // OK
    immutable s3 = f(0); // error, the context doesn't require CTFE

Allow previously rejected but logically valid code to compile.

Function return type is treated differently depending on a calling context
(CTFE or not) which complicates language type system.

Jan 20 2015