[Issue 23229] New: struct used as UDA with opDispatch errors with "variable `impl` cannot be modified at compile time" if it includes a call to writeln

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jul 4 10:51:24 UTC 2022


https://issues.dlang.org/show_bug.cgi?id=23229

          Issue ID: 23229
           Summary: struct used as UDA with opDispatch errors with
                    "variable `impl` cannot be modified at compile time"
                    if it includes a call to writeln
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: zorael at gmail.com

Manjaro/Arch x86_64, dmd v2.100.0, ldc 1.29.0.

A struct used as a UDA fails to compile if it has an `opDispatch` which invokes
writeln.

---

import std.stdio;

struct UDA
{
    string _hello;

    void opDispatch(string var, T)(T value)
    {
        writeln("opDispatch ", var);
        enum realVar = '_' ~ var;
        mixin(realVar) = value;
    }
}

@(UDA()
    .hello("hi")
)
struct Foo {}

void main() {}

---

/dlang/dmd/linux/bin64/../../src/phobos/std/stdio.d(5190): Error: variable
`impl` cannot be modified at compile time
/dlang/dmd/linux/bin64/../../src/phobos/std/stdio.d(4130):        called from
here: `makeGlobal()`
/dlang/dmd/linux/bin64/../../src/phobos/std/stdio.d(4235):        called from
here: `trustedStdout()`
onlineapp.d(9):        called from here: `writeln("opDispatch ", "hello")`
onlineapp.d(16):        called from here: `UDA(null).opDispatch("hi")`

--


More information about the Digitalmars-d-bugs mailing list