www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22261] New: import expression does not work in __ctfe context


          Issue ID: 22261
           Summary: import expression does not work in __ctfe context
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: ttanjo gmail.com

It would be nice if we can use import expressions in __ctfe context as shown

run.dlang.io: https://t.co/ui274K3Vqa?amp=1

import std;

void main()
    enum str = load(__FILE__);

auto load(string path)
    if (__ctfe)
        return import(path);
        return readText(path);

It fails to compile with the following message:
 rdmd playground.d
onlineapp.d(12): Error: variable `path` cannot be read at compile time ``` --
Sep 01 2021