Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit location of original var def for duplicate var errors #2126

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion DMCompiler/DM/DMCodeTree.Vars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,15 @@ 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
if (!varDef.Location.InDMStandard) { // Duplicate instance vars are not an error in DMStandard
compiler.Emit(WarningCode.InvalidVarDefinition, varDef.Location,
$"Duplicate definition of var \"{VarName}\"");
var variable = dmObject.GetVariable(VarName);
if(variable!.Value is not null)
Dismissed Show dismissed Hide dismissed
compiler.Emit(WarningCode.InvalidVarDefinition, variable.Value.Location,
ike709 marked this conversation as resolved.
Show resolved Hide resolved
$"Previous 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
Loading