Skip to content

Commit 4ce4bf8

Browse files
Move IndexExp.markSettingAAElem into expressionsem (#21600)
1 parent ae7f520 commit 4ce4bf8

2 files changed

Lines changed: 24 additions & 23 deletions

File tree

compiler/src/dmd/expression.d

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4032,29 +4032,6 @@ extern (C++) final class IndexExp : BinExp
40324032
return true;
40334033
}
40344034

4035-
extern (D) Expression markSettingAAElem()
4036-
{
4037-
if (e1.type.toBasetype().ty == Taarray)
4038-
{
4039-
Type t2b = e2.type.toBasetype();
4040-
if (t2b.ty == Tarray && t2b.nextOf().isMutable())
4041-
{
4042-
error(loc, "associative arrays can only be assigned values with immutable keys, not `%s`", e2.type.toChars());
4043-
return ErrorExp.get();
4044-
}
4045-
modifiable = true;
4046-
4047-
if (auto ie = e1.isIndexExp())
4048-
{
4049-
Expression ex = ie.markSettingAAElem();
4050-
if (ex.op == EXP.error)
4051-
return ex;
4052-
assert(ex == e1);
4053-
}
4054-
}
4055-
return this;
4056-
}
4057-
40584035
override void accept(Visitor v)
40594036
{
40604037
v.visit(this);

compiler/src/dmd/expressionsem.d

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4012,6 +4012,30 @@ private bool checkNestedFuncReference(FuncDeclaration fd, Scope* sc, Loc loc)
40124012
return false;
40134013
}
40144014

4015+
private Expression markSettingAAElem(IndexExp ie)
4016+
{
4017+
if (ie.e1.type.toBasetype().ty != Taarray)
4018+
return ie;
4019+
4020+
Type t2b = ie.e2.type.toBasetype();
4021+
if (t2b.ty == Tarray && t2b.nextOf().isMutable())
4022+
{
4023+
error(ie.loc, "associative arrays can only be assigned values with immutable keys, not `%s`", ie.e2.type.toChars());
4024+
return ErrorExp.get();
4025+
}
4026+
ie.modifiable = true;
4027+
4028+
if (auto ie2 = ie.e1.isIndexExp())
4029+
{
4030+
Expression ex = ie2.markSettingAAElem();
4031+
if (ex.op == EXP.error)
4032+
return ex;
4033+
assert(ex == ie.e1);
4034+
}
4035+
4036+
return ie;
4037+
}
4038+
40154039
private extern (C++) final class ExpressionSemanticVisitor : Visitor
40164040
{
40174041
alias visit = Visitor.visit;

0 commit comments

Comments
 (0)