[Dlang-internal] Detect CTFE in AssignExp:semantic

Martin Nowak via Dlang-internal dlang-internal at puremagic.com
Mon Jan 16 17:26:54 PST 2017


On 01/16/2017 11:22 PM, Lucia Cojocaru wrote:
> druntime
> https://github.com/somzzz/druntime/commit/fb51f34cb0bdd96daaa92ab22773bf93778d4d11

https://github.com/somzzz/druntime/commit/fb51f34cb0bdd96daaa92ab22773bf93778d4d11#commitcomment-20497420

> dmd
> https://github.com/somzzz/dmd/commit/b3cf4625ce733e4b3f219bcd5069d9042430b594

Looks like you're running into some issues with the "magic" temporary
variables generated by the compiler.

https://github.com/dlang/dmd/blob/a5f823a59d11bb02a56384891eb80a55af467e00/src/statementsem.d#L886-L907

The error is generated here
https://github.com/dlang/dmd/blob/c1d138cc3860ecf8cbe06090cc321f4d5502b6ee/src/dinterpret.d#L2441

with hasValue(v) == false meaning that the variable was not interpreted
(put on the stack) before usage.
I guess this happens because you're actually converting the
initialization of the temporary into a function call.

T __r154 = slice[];

lowered into:

_d_arraycopyT(__r154, slice[]);

So the function call gets interpreted before the variable was
initialized by CTFE, not exactly sure how to best resolve this.

Maybe simply skip lowering ConstructExp (subclass of AssignExp used for
construction) for now.
You can recognize construction inside of AssignExp by looking at the op,
`op == TOKconstruct`.

-Martin


More information about the Dlang-internal mailing list