Skip to content

Commit

Permalink
Compile error when outputting to const vars in for() loops
Browse files Browse the repository at this point in the history
  • Loading branch information
ike709 committed Dec 7, 2024
1 parent e638422 commit 85efc53
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// COMPILE ERROR
// COMPILE ERROR OD0501

/datum
var/const/idx = 0
Expand Down
5 changes: 5 additions & 0 deletions DMCompiler/DM/Builders/DMProcBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,11 @@ public void ProcessStatementFor(DMASTProcStatementFor statementFor) {
outputExpr = exprRange.Value;
}

if (outputExpr is DMASTIdentifier identifier &&
dmObject.GetVariable(identifier.Identifier) is { IsConst: true }) {
compiler.Emit(WarningCode.WriteToConstant, outputExpr.Location, "Cannot change constant value");
}

var outputVar = _exprBuilder.Create(outputExpr);

var start = _exprBuilder.Create(exprRange.StartRange);
Expand Down

0 comments on commit 85efc53

Please sign in to comment.