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

Disallow var defines on /world and /list #2206

Merged
Merged
Changes from all commits
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
25 changes: 18 additions & 7 deletions DMCompiler/DM/DMCodeTree.Vars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public override bool TryDefineVar(DMCompiler compiler, int pass) {
if (!compiler.DMObjectTree.TryGetDMObject(owner, out var dmObject))
return false;

if (AlreadyExists(compiler, dmObject)) {
if (CheckCantDefine(compiler, dmObject)) {
_defined = true;
return true;
}
Expand Down Expand Up @@ -162,12 +162,23 @@ private bool HandleInstanceVar(DMCompiler compiler, DMObject dmObject) {
return true;
}

private bool AlreadyExists(DMCompiler compiler, DMObject dmObject) {
// "type" and "tag" can only be defined in DMStandard
if (VarName is "type" or "tag" && !varDef.Location.InDMStandard) {
compiler.Emit(WarningCode.InvalidVarDefinition, varDef.Location,
$"Cannot redefine built-in var \"{VarName}\"");
return true;
private bool CheckCantDefine(DMCompiler compiler, DMObject dmObject) {
if (!compiler.Settings.NoStandard) {
var inStandard = varDef.Location.InDMStandard;

// "type" and "tag" can only be defined in DMStandard
if (VarName is "type" or "tag" && !inStandard) {
compiler.Emit(WarningCode.InvalidVarDefinition, varDef.Location,
$"Cannot redefine built-in var \"{VarName}\"");
return true;
}

// Vars on /world and /list can only be defined in DMStandard
if ((dmObject.Path == DreamPath.World || dmObject.Path == DreamPath.List) && !inStandard) {
compiler.Emit(WarningCode.InvalidVarDefinition, varDef.Location,
$"Cannot define a var on type {dmObject.Path}");
return true;
}
}

//DMObjects store two bundles of variables; the statics in GlobalVariables and the non-statics in Variables.
Expand Down
Loading