From 8a7abfc0e771f3f673764b79525aaf844ac3bbac Mon Sep 17 00:00:00 2001 From: ike709 Date: Sat, 7 Dec 2024 19:02:54 -0600 Subject: [PATCH] Implement `initial()` for `arglist()` (#2123) Co-authored-by: ike709 --- .../DMProject/Broken Tests/Procs/Arglist/initial.dm | 6 ------ Content.Tests/DMProject/Tests/Procs/Arglist/initial.dm | 6 ++++++ DMCompiler/DM/Expressions/Builtins.cs | 7 +++++++ 3 files changed, 13 insertions(+), 6 deletions(-) delete mode 100644 Content.Tests/DMProject/Broken Tests/Procs/Arglist/initial.dm create mode 100644 Content.Tests/DMProject/Tests/Procs/Arglist/initial.dm diff --git a/Content.Tests/DMProject/Broken Tests/Procs/Arglist/initial.dm b/Content.Tests/DMProject/Broken Tests/Procs/Arglist/initial.dm deleted file mode 100644 index 2e77abf518..0000000000 --- a/Content.Tests/DMProject/Broken Tests/Procs/Arglist/initial.dm +++ /dev/null @@ -1,6 +0,0 @@ - -/proc/_initial(...) - return initial(arglist(args)) - -/proc/RunTest() - return \ No newline at end of file diff --git a/Content.Tests/DMProject/Tests/Procs/Arglist/initial.dm b/Content.Tests/DMProject/Tests/Procs/Arglist/initial.dm new file mode 100644 index 0000000000..716becd5d4 --- /dev/null +++ b/Content.Tests/DMProject/Tests/Procs/Arglist/initial.dm @@ -0,0 +1,6 @@ + +/proc/_initial(...) + ASSERT(initial(arglist(args))[1] == "foo") + +/proc/RunTest() + _initial("foo") diff --git a/DMCompiler/DM/Expressions/Builtins.cs b/DMCompiler/DM/Expressions/Builtins.cs index 4b7ec230b6..e11b037cf7 100644 --- a/DMCompiler/DM/Expressions/Builtins.cs +++ b/DMCompiler/DM/Expressions/Builtins.cs @@ -505,6 +505,13 @@ public override void EmitPushValue(ExpressionContext ctx) { return; } + if (Expression is Arglist arglist) { + // This happens silently in BYOND + ctx.Compiler.Emit(WarningCode.PointlessBuiltinCall, Location, "calling initial() on arglist() returns the current value"); + arglist.EmitPushArglist(ctx); + return; + } + ctx.Compiler.Emit(WarningCode.BadArgument, Expression.Location, $"can't get initial value of {Expression}"); ctx.Proc.Error(); }