www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23229] New: struct used as UDA with opDispatch errors with

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 puremagic.com
          Reporter: zorael 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")`

--
Jul 04 2022