Bug 21296 – std.variant.Variant cannot be initialized with immutable AA
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2020-10-07T09:34:43Z
Last change time
2020-10-07T13:08:08Z
Assigned to
No Owner
Creator
Tomoya Tanjo
Comments
Comment #0 by ttanjo — 2020-10-07T09:34:43Z
I confirmed this issue with dmd 2.094.0 on my WSL environment and with run.dlang.io (https://run.dlang.io/is/EI2fhc).
- How to reproduce:
```
$ cat sample.d
import std.variant;
void main()
{
immutable aa = ["0":0];
auto v = Variant(aa);
}
$ dmd sample.d
```
- Expected behavior: The dmd command successfully compiles the source code and generates an executable file.
- Actual behavior: It fails compiling with the following messages:
```
$ dmd sample.d
/home/ttanjo/dlang/dmd-2.094.0/linux/bin64/../../src/phobos/std/variant.d(490): Error: cannot modify immutable expression (*zis)[args[1].get()]
/home/ttanjo/dlang/dmd-2.094.0/linux/bin64/../../src/phobos/std/variant.d(707): Error: template instance std.variant.VariantN!32LU.VariantN.handler!(immutable(int[string])) error instantiating
/home/ttanjo/dlang/dmd-2.094.0/linux/bin64/../../src/phobos/std/variant.d(604): instantiated from here: opAssign!(immutable(int[string]))
sample.d(6): instantiated from here: __ctor!(immutable(int[string]))
```
I guess this issue is the source of the problem of Issue 13930.
Comment #1 by dlang-bot — 2020-10-07T13:08:08Z
dlang/phobos pull request #7652 "Fix issue 21296 - std.variant.Variant cannot be initialized with immu…" was merged into master:
- 772c7fcf833d22ccb89f1e9608ce3ee92dfe2c73 by Tomoya Tanjo:
Fix issue 21296 - std.variant.Variant cannot be initialized with immutable AA
https://github.com/dlang/phobos/pull/7652