diff --git a/Content.Tests/DMProject/Tests/Arg/ProcArgumentGlobal_lint.dm b/Content.Tests/DMProject/Tests/Arg/ProcArgumentGlobal_lint.dm new file mode 100644 index 0000000000..5356fb9aad --- /dev/null +++ b/Content.Tests/DMProject/Tests/Arg/ProcArgumentGlobal_lint.dm @@ -0,0 +1,8 @@ +// COMPILE ERROR OD2211 +#pragma ProcArgumentGlobal error + +/proc/foo(/var/bar) + return + +/proc/RunTest() + return diff --git a/DMCompiler/Compiler/CompilerError.cs b/DMCompiler/Compiler/CompilerError.cs index ed7f43bd81..92781d038e 100644 --- a/DMCompiler/Compiler/CompilerError.cs +++ b/DMCompiler/Compiler/CompilerError.cs @@ -49,6 +49,7 @@ public enum WarningCode { FallbackBuiltinArgument = 2208, // A builtin (sin(), cos(), etc) with an invalid/fallback argument 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 MalformedRange = 2300, InvalidRange = 2301, InvalidSetStatement = 2302, diff --git a/DMCompiler/Compiler/DM/DMParser.cs b/DMCompiler/Compiler/DM/DMParser.cs index 48612218b8..bf7e025353 100644 --- a/DMCompiler/Compiler/DM/DMParser.cs +++ b/DMCompiler/Compiler/DM/DMParser.cs @@ -1723,6 +1723,10 @@ private List DefinitionParameters(out bool wasIndeterm DMASTPath? path = Path(); if (path != null) { + if (path.Path.PathString.StartsWith("/var/")) { + Emit(WarningCode.ProcArgumentGlobal, $"Proc argument \"{path.Path.PathString}\" starting with \"/var/\" will create a global variable. Replace with \"{path.Path.PathString[1..]}\""); + } + var loc = Current().Location; Whitespace(); diff --git a/DMCompiler/DMStandard/DefaultPragmaConfig.dm b/DMCompiler/DMStandard/DefaultPragmaConfig.dm index c91ebb324d..c67eb91610 100644 --- a/DMCompiler/DMStandard/DefaultPragmaConfig.dm +++ b/DMCompiler/DMStandard/DefaultPragmaConfig.dm @@ -31,6 +31,7 @@ #pragma AmbiguousResourcePath warning #pragma SuspiciousSwitchCase warning #pragma PointlessPositionalArgument warning +#pragma ProcArgumentGlobal warning // Ref BYOND issue https://www.byond.com/forum/post/2830750 // 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)