From f1912e6cac297c29a4901e4f1d90052100eb0447 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 | 6 +++++- 3 files changed, 9 insertions(+), 6 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..dbdd5d5666b5 100644 --- a/compiler/test/fail_compilation/fail6795.d +++ b/compiler/test/fail_compilation/fail6795.d @@ -8,9 +8,9 @@ fail_compilation/fail6795.d(22): Error: cannot modify expression `[0][0]` becaus 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(30): Error: cannot modify expression `Some["zz"]` because it is not an lvalue --- */ - void test_wrong_line_num() { enum int[1] sa = [0]; @@ -24,4 +24,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; }