Skip to content

Commit

Permalink
Fix bugzilla 24845 - Compiler error when trying to assign to an AA va…
Browse files Browse the repository at this point in the history
…lue of an enum instance
  • Loading branch information
dkorpel authored and dlang-bot committed Nov 25, 2024
1 parent 949cb11 commit 519d388
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
7 changes: 3 additions & 4 deletions compiler/src/dmd/expression.d
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/compilable/compile1.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion compiler/test/fail_compilation/fail6795.d
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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;
}

0 comments on commit 519d388

Please sign in to comment.