Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugzilla 24845 - Compiler error when trying to assign to an AA va… #17094

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Loading