Bug 23229 – struct used as UDA with opDispatch errors with "variable `impl` cannot be modified at compile time" if it includes a call to writeln

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2022-07-04T10:51:24Z
Last change time
2024-12-13T19:23:43Z
Assigned to
No Owner
Creator
JR
Moved to GitHub: dmd#18115 →

Comments

Comment #0 by zorael — 2022-07-04T10:51:24Z
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")`
Comment #1 by robert.schadek — 2024-12-13T19:23:43Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18115 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB