digitalmars.D.bugs - [Issue 14018] New: Treat CTFE-able functions as pure in CTFE-only
- via Digitalmars-d-bugs (39/39) Jan 20 2015 https://issues.dlang.org/show_bug.cgi?id=14018
https://issues.dlang.org/show_bug.cgi?id=14018 Issue ID: 14018 Summary: Treat CTFE-able functions as pure in CTFE-only contexts 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) { if(i) ++g; 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 } --- Pros: Allow previously rejected but logically valid code to compile. Cons: Function return type is treated differently depending on a calling context (CTFE or not) which complicates language type system. --
Jan 20 2015