mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-07 19:36:06 +03:00
Keep lvalue-ness when casting AA to another AA (#3179)
Fixes issue #3162.
This commit is contained in:
parent
6128a79eed
commit
ad400ff2d0
2 changed files with 19 additions and 6 deletions
|
@ -675,6 +675,12 @@ DValue *DtoCast(Loc &loc, DValue *val, Type *to) {
|
||||||
Type *totype = to->toBasetype();
|
Type *totype = to->toBasetype();
|
||||||
|
|
||||||
if (fromtype->ty == Taarray) {
|
if (fromtype->ty == Taarray) {
|
||||||
|
if (totype->ty == Taarray) {
|
||||||
|
// reinterpret-cast keeping lvalue-ness, IR types will match up
|
||||||
|
if (val->isLVal())
|
||||||
|
return new DLValue(to, DtoLVal(val));
|
||||||
|
return new DImValue(to, DtoRVal(val));
|
||||||
|
}
|
||||||
// DMD allows casting AAs to void*, even if they are internally
|
// DMD allows casting AAs to void*, even if they are internally
|
||||||
// implemented as structs.
|
// implemented as structs.
|
||||||
if (totype->ty == Tpointer) {
|
if (totype->ty == Tpointer) {
|
||||||
|
@ -727,12 +733,6 @@ DValue *DtoCast(Loc &loc, DValue *val, Type *to) {
|
||||||
return DtoCastStruct(loc, val, to);
|
return DtoCastStruct(loc, val, to);
|
||||||
case Tnull:
|
case Tnull:
|
||||||
return DtoNullValue(to, loc);
|
return DtoNullValue(to, loc);
|
||||||
case Taarray:
|
|
||||||
if (totype->ty == Taarray) {
|
|
||||||
// Do nothing, the types will match up anyway.
|
|
||||||
return new DImValue(to, DtoRVal(val));
|
|
||||||
}
|
|
||||||
// fall-through
|
|
||||||
default:
|
default:
|
||||||
error(loc, "invalid cast from `%s` to `%s`", val->type->toChars(),
|
error(loc, "invalid cast from `%s` to `%s`", val->type->toChars(),
|
||||||
to->toChars());
|
to->toChars());
|
||||||
|
|
13
tests/compilable/gh3162.d
Normal file
13
tests/compilable/gh3162.d
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
// RUN: %ldc -run %s
|
||||||
|
|
||||||
|
shared struct Queue
|
||||||
|
{
|
||||||
|
int[int] map;
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
auto queue = Queue();
|
||||||
|
( cast(int[int]) queue.map )[1] = 2;
|
||||||
|
assert(queue.map[1] == 2);
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue