From a430bd7c9286d98476b16dad1d638ca591bdec2d Mon Sep 17 00:00:00 2001 From: Dennis Korpel Date: Mon, 25 Nov 2024 13:20:46 +0100 Subject: [PATCH] Fix bugzilla 24845 - Compiler error when trying to assign to an AA value of an enum instance --- compiler/src/dmd/expression.d | 7 +++---- compiler/test/compilable/compile1.d | 2 +- compiler/test/fail_compilation/fail6795.d | 17 +++++++++++------ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/compiler/src/dmd/expression.d b/compiler/src/dmd/expression.d index 3c79b02caa02..dc72b3a8df1b 100644 --- a/compiler/src/dmd/expression.d +++ b/compiler/src/dmd/expression.d @@ -4143,10 +4143,9 @@ extern (C++) final class IndexExp : BinExp override bool isLvalue() { - if (e1.op == EXP.assocArrayLiteral) - return false; - if (e1.type.ty == Tsarray || - (e1.op == EXP.index && e1.type.ty != Tarray)) + auto t1b = e1.type.toBasetype(); + if (t1b.isTypeAArray() || t1b.isTypeSArray() || + (e1.isIndexExp() && t1b != t1b.isTypeDArray())) { return e1.isLvalue(); } diff --git a/compiler/test/compilable/compile1.d b/compiler/test/compilable/compile1.d index 676108f68cfa..15973cf11f92 100644 --- a/compiler/test/compilable/compile1.d +++ b/compiler/test/compilable/compile1.d @@ -861,7 +861,7 @@ S14166 s14166; struct X14166 { this(int) { } X14166 opAssign(int) { return this; } } X14166[int] aa14166; -X14166[int] makeAA14166() { return aa14166; } +ref X14166[int] makeAA14166() { return aa14166; } struct Tup14166(T...) { T field; alias field this; } Tup14166!(int, int) tup14166; diff --git a/compiler/test/fail_compilation/fail6795.d b/compiler/test/fail_compilation/fail6795.d index 26d442964988..05b5de4e8267 100644 --- a/compiler/test/fail_compilation/fail6795.d +++ b/compiler/test/fail_compilation/fail6795.d @@ -2,12 +2,13 @@ /* TEST_OUTPUT: --- -fail_compilation/fail6795.d(19): Error: cannot modify expression `[0][0]` because it is not an lvalue -fail_compilation/fail6795.d(20): Error: cannot modify expression `[0:0][0]` because it is not an lvalue -fail_compilation/fail6795.d(22): Error: cannot modify expression `[0][0]` because it is not an lvalue -fail_compilation/fail6795.d(23): Error: cannot modify expression `[0:0][0]` because it is not an lvalue -fail_compilation/fail6795.d(25): Error: cannot take address of expression `[0][0]` because it is not an lvalue -fail_compilation/fail6795.d(26): Error: cannot take address of expression `[0:0][0]` because it is not an lvalue +fail_compilation/fail6795.d(20): Error: cannot modify expression `[0][0]` because it is not an lvalue +fail_compilation/fail6795.d(21): Error: cannot modify expression `[0:0][0]` because it is not an lvalue +fail_compilation/fail6795.d(23): Error: cannot modify expression `[0][0]` because it is not an lvalue +fail_compilation/fail6795.d(24): Error: cannot modify expression `[0:0][0]` because it is not an lvalue +fail_compilation/fail6795.d(26): Error: cannot take address of expression `[0][0]` because it is not an lvalue +fail_compilation/fail6795.d(27): Error: cannot take address of expression `[0:0][0]` because it is not an lvalue +fail_compilation/fail6795.d(30): Error: cannot modify expression `Some["zz"]` because it is not an lvalue --- */ @@ -24,4 +25,8 @@ void test_wrong_line_num() auto ps = &sa[0]; auto pa = &aa[0]; + + // https://issues.dlang.org/show_bug.cgi?id=24845 + enum Maps : int[string] { Some = ["aa" : 12], Other = ["bb" : 24] } + Maps.Some["zz"] = 44; }