D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 21296 - std.variant.Variant cannot be initialized with immutable AA
Summary: std.variant.Variant cannot be initialized with immutable AA
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-10-07 09:34 UTC by Tomoya Tanjo
Modified: 2020-10-07 13:08 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Tomoya Tanjo 2020-10-07 09:34:43 UTC
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 Dlang Bot 2020-10-07 13:08:08 UTC
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