From 621460e3131a5bd0bb40ff2119b1b9b8e784fbfa Mon Sep 17 00:00:00 2001 From: ike709 Date: Sun, 8 Dec 2024 21:36:12 -0600 Subject: [PATCH] Emit location of original var def for duplicate var errors (#2126) Co-authored-by: ike709 --- DMCompiler/DM/DMCodeTree.Vars.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/DMCompiler/DM/DMCodeTree.Vars.cs b/DMCompiler/DM/DMCodeTree.Vars.cs index b259047fb3..3c399703de 100644 --- a/DMCompiler/DM/DMCodeTree.Vars.cs +++ b/DMCompiler/DM/DMCodeTree.Vars.cs @@ -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");