Bug 22261 – import expression does not work in __ctfe context
Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-09-01T09:45:08Z
Last change time
2021-12-19T01:26:52Z
Assigned to
No Owner
Creator
Tomoya Tanjo
Comments
Comment #0 by ttanjo — 2021-09-01T09:45:08Z
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
```
Comment #1 by moonlightsentinel — 2021-12-19T01:26:52Z