[Issue 22261] New: import expression does not work in __ctfe context
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Sep 1 09:45:08 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=22261
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 at puremagic.com
Reporter: ttanjo at gmail.com
It would be nice if we can use import expressions in __ctfe context as shown
below.
run.dlang.io: https://t.co/ui274K3Vqa?amp=1
```dlang
import std;
void main()
{
enum str = load(__FILE__);
}
auto load(string path)
{
if (__ctfe)
{
return import(path);
}
else
{
return readText(path);
}
}
```
It fails to compile with the following message:
```console
> rdmd playground.d
onlineapp.d(12): Error: variable `path` cannot be read at compile time
```
--
More information about the Digitalmars-d-bugs
mailing list