SumType!(A,B) != SumType!(B,A) - a bug?
Nickolay Bukreyev
buknik95 at ya.ru
Fri Dec 29 12:27:19 UTC 2023
On Tuesday, 26 December 2023 at 19:19:08 UTC, Paul Backus wrote:
> I think this is probably a compiler bug, but it's hard to tell
> without a reduced example.
```d
union A {
int x;
int[] arr;
}
union B {
int[] arr;
int x;
}
A createA() /+pure+/ { return A.init; }
B createB() /+pure+/ { return B.init; }
void main() {
immutable a = createA(); // OK
immutable b = createB(); // cannot implicitly convert
expression `createB()` of type `B` to `immutable(B)`
}
```
If we mark `createB` pure, it will compile successfully. This
behaviour is described in the spec: `createB` becomes a [pure
factory
function](https://dlang.org/spec/function.html#pure-factory-functions).
I believe DMD should issue an error for `A` as well.
More information about the Digitalmars-d
mailing list