From fdcf9aff8d917526838f5dd42d07ef2488365ef6 Mon Sep 17 00:00:00 2001 From: ike709 Date: Sat, 26 Oct 2024 23:58:29 -0500 Subject: [PATCH 1/3] Lint for `/var/` in proc args --- .../DMProject/Tests/Arg/ProcArgumentGlobal_lint.dm | 8 ++++++++ DMCompiler/Compiler/CompilerError.cs | 1 + DMCompiler/Compiler/DM/DMParser.cs | 4 ++++ DMCompiler/DMStandard/DefaultPragmaConfig.dm | 1 + 4 files changed, 14 insertions(+) create mode 100644 Content.Tests/DMProject/Tests/Arg/ProcArgumentGlobal_lint.dm 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..bd6fde0ff7 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(/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..26f9a9ef7e 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) From d6575cfafea9266f564b6bc1003fd646b2b09e21 Mon Sep 17 00:00:00 2001 From: ike709 Date: Sun, 27 Oct 2024 00:00:58 -0500 Subject: [PATCH 2/3] let's be super safe --- DMCompiler/Compiler/DM/DMParser.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DMCompiler/Compiler/DM/DMParser.cs b/DMCompiler/Compiler/DM/DMParser.cs index 26f9a9ef7e..bf7e025353 100644 --- a/DMCompiler/Compiler/DM/DMParser.cs +++ b/DMCompiler/Compiler/DM/DMParser.cs @@ -1723,7 +1723,7 @@ private List DefinitionParameters(out bool wasIndeterm DMASTPath? path = Path(); if (path != null) { - if (path.Path.PathString.StartsWith("/var")) { + 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..]}\""); } From 9ef146ae00faf1a73eb64b0f83c2b59036d2a703 Mon Sep 17 00:00:00 2001 From: ike709 Date: Sun, 27 Oct 2024 00:28:46 -0500 Subject: [PATCH 3/3] fix comment --- DMCompiler/Compiler/CompilerError.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DMCompiler/Compiler/CompilerError.cs b/DMCompiler/Compiler/CompilerError.cs index bd6fde0ff7..92781d038e 100644 --- a/DMCompiler/Compiler/CompilerError.cs +++ b/DMCompiler/Compiler/CompilerError.cs @@ -49,7 +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(/var/foo)" makes the arg a global var. Ref https://www.byond.com/forum/post/2830750 + 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,