Skip to content

Commit

Permalink
Emit location of original var def for duplicate var errors (#2126)
Browse files Browse the repository at this point in the history
Co-authored-by: ike709 <[email protected]>
  • Loading branch information
ike709 and ike709 authored Dec 9, 2024
1 parent 8a7abfc commit 621460e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions DMCompiler/DM/DMCodeTree.Vars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,16 @@ private bool AlreadyExists(DMCompiler compiler, DMObject dmObject) {
$"Duplicate definition of static var \"{VarName}\"");
return true;
} else if (dmObject.HasLocalVariable(VarName)) {
if (!varDef.Location.InDMStandard) // Duplicate instance vars are not an error in DMStandard
compiler.Emit(WarningCode.InvalidVarDefinition, varDef.Location,
if (!varDef.Location.InDMStandard) { // Duplicate instance vars are not an error in DMStandard
var variable = dmObject.GetVariable(VarName);
if(variable!.Value is not null)
compiler.Emit(WarningCode.InvalidVarDefinition, varDef.Location,
$"Duplicate definition of var \"{VarName}\". Previous definition at {variable.Value.Location}");
else
compiler.Emit(WarningCode.InvalidVarDefinition, varDef.Location,
$"Duplicate definition of var \"{VarName}\"");
}

return true;
} else if (IsStatic && VarName == "vars" && dmObject == compiler.DMObjectTree.Root) {
compiler.Emit(WarningCode.InvalidVarDefinition, varDef.Location, "Duplicate definition of global.vars");
Expand Down

0 comments on commit 621460e

Please sign in to comment.