Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions DMCompiler/Compiler/CompilerError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public enum WarningCode {
PointlessScopeOperator = 2209,
PointlessPositionalArgument = 2210,
ProcArgumentGlobal = 2211, // Prepending "/" on a proc arg (e.g. "/proc/example(/var/foo)" makes the arg a global var. Ref https://www.byond.com/forum/post/2830750
AmbiguousVarStatic = 2212, // Referencing a static variable when an instance variable with the same name exists
MalformedRange = 2300,
InvalidRange = 2301,
InvalidSetStatement = 2302,
Expand Down
5 changes: 4 additions & 1 deletion DMCompiler/DM/Builders/DMExpressionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -554,13 +554,16 @@ private static DMExpression BuildIdentifier(DMASTIdentifier identifier, DMObject
}

var field = dmObject.GetVariable(name);
if (field != null) {
if (field != null && CurrentScopeMode == ScopeMode.Normal) {
return new Field(identifier.Location, field, field.ValType);
}

var globalId = proc?.GetGlobalVariableId(name) ?? dmObject.GetGlobalVariableId(name);

if (globalId != null) {
if (field is not null)
DMCompiler.Emit(WarningCode.AmbiguousVarStatic, identifier.Location, $"Static var definition cannot reference instance variable \"{name}\" but a global exists");

var globalVar = DMObjectTree.Globals[globalId.Value];
var global = new GlobalField(identifier.Location, globalVar.Type, globalId.Value, globalVar.ValType);
return global;
Expand Down
5 changes: 4 additions & 1 deletion DMCompiler/DM/Builders/DMProcBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,11 @@ public void ProcessStatementSpawn(DMASTProcStatementSpawn statementSpawn) {
proc.AddLabel(afterSpawnLabel);
}

/// <remarks>
/// Global/static var declarations are handled by <see cref="DMCodeTree.ProcGlobalVarNode" />
/// </remarks>
public void ProcessStatementVarDeclaration(DMASTProcStatementVarDeclaration varDeclaration) {
if (varDeclaration.IsGlobal) { return; } //Currently handled by DMObjectBuilder
if (varDeclaration.IsGlobal) { return; }

DMExpression value;
if (varDeclaration.Value != null) {
Expand Down
3 changes: 2 additions & 1 deletion DMCompiler/DMStandard/DefaultPragmaConfig.dm
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#pragma SuspiciousSwitchCase warning
#pragma PointlessPositionalArgument warning
#pragma ProcArgumentGlobal warning // Ref BYOND issue https://www.byond.com/forum/post/2830750
#pragma AmbiguousVarStatic warning // https://github.com/OpenDreamProject/OpenDream/issues/997
// NOTE: The next few pragmas are for OpenDream's experimental type checker
// This feature is still in development, elevating these pragmas outside of local testing is discouraged
// An RFC to finalize this feature is coming soon(TM)
Expand All @@ -48,7 +49,7 @@
#pragma EmptyBlock notice
#pragma EmptyProc disabled // NOTE: If you enable this in OD's default pragma config file, it will emit for OD's DMStandard. Put it in your codebase's pragma config file.
#pragma UnsafeClientAccess disabled // NOTE: Only checks for unsafe accesses like "client.foobar" and doesn't consider if the client was already null-checked earlier in the proc
#pragma AssignmentInConditional warning
#pragma AssignmentInConditional warning
#pragma PickWeightedSyntax disabled
#pragma AmbiguousInOrder warning
#pragma RuntimeSearchOperator disabled
Loading