Skip to content

Commit

Permalink
fix: #485
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsDeltin committed May 23, 2024
1 parent fc77699 commit 4f8b7e5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public interface IAssignmentOperation
{
AssignmentOperator Operator { get; }
CodeType ValueType { get; }
bool IsModification { get; }
void Validate(ParseInfo parseInfo, DocRange range, IExpression value);
void Resolve(AssignmentOperationInfo assignmentOperationInfo);
}
Expand All @@ -18,6 +19,7 @@ public class AssignmentOperation : IAssignmentOperation
{
public AssignmentOperator Operator { get; }
public CodeType ValueType { get; }
public bool IsModification => Operator is not AssignmentOperator.Equal;
private readonly Action<ValidateOperationParams>? _validate;
private readonly Action<AssignmentOperationInfo> _action;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ public SetVariableAction(ParseInfo parseInfo, Scope scope, Assignment assignment
public void Translate(ActionSet actionSet)
{
var elements = _variableResolve.ParseElements(actionSet);
_operation.Resolve(new AssignmentOperationInfo(_comment, actionSet, elements, _value.Parse(actionSet.SetTempAssign(new(elements.IndexReference)))));

// Do not use TempAssign if the operation is a modification and not an overwrite. (#485)
var valueActionSet = _operation.IsModification ? actionSet : actionSet.SetTempAssign(new(elements.IndexReference));

var value = _value.Parse(valueActionSet);
_operation.Resolve(new AssignmentOperationInfo(_comment, actionSet, elements, value));
}

public void OutputComment(FileDiagnostics diagnostics, DocRange range, string comment) => _comment = comment;
Expand Down

0 comments on commit 4f8b7e5

Please sign in to comment.