SumType!(A,B) != SumType!(B,A) - a bug?

Andrey Zherikov andrey.zherikov at gmail.com
Tue Dec 26 19:05:08 UTC 2023


Here is the code:
```d
struct A {}
struct B { int[] i; }

immutable s1 = SumType!(A,B)(B.init);    // (1) compiles
immutable s2 = SumType!(B,A)(B.init);    // (2) compilation error
```

Compilation error for (2):
> onlineapp.d(9): Error: cannot implicitly convert expression 
> `SumType(Storage(B(null), ), cast(ubyte)0u).this(B(null))` of 
> type `SumType!(B, A)` to `immutable(SumType!(B, A))`
> onlineapp.d(9):        `s2 = SumType(Storage(B(null), ), 
> cast(ubyte)0u).this(B(null))` is the first assignment of `s2` 
> therefore it represents its initialization
> onlineapp.d(9):        `opAssign` methods are not used for 
> initialization, but for subsequent assignments

Questions:
- Should (1) and (2) behave the same way?
- Is there anything I can do with type `A` to make (1) fail to 
compile the same way as (2)?


More information about the Digitalmars-d mailing list