Here is the code:
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
Ato make (1) fail to compile the same way as (2)?
Permalink
Reply