diff --git a/src/MoonSharp.Interpreter/Execution/VM/Processor/Processor_InstructionLoop.cs b/src/MoonSharp.Interpreter/Execution/VM/Processor/Processor_InstructionLoop.cs index 38c0f63e..29f97873 100644 --- a/src/MoonSharp.Interpreter/Execution/VM/Processor/Processor_InstructionLoop.cs +++ b/src/MoonSharp.Interpreter/Execution/VM/Processor/Processor_InstructionLoop.cs @@ -351,15 +351,25 @@ internal string PerformMessageDecorationBeforeUnwind(DynValue messageHandler, st - private void AssignLocal(SymbolRef symref, DynValue value) + private void AssignLocal(SymbolRef symref, DynValue value, bool isOmittedArgumentInFunctionCall = false) { var stackframe = m_ExecutionStack.Peek(); - DynValue v = stackframe.LocalScope[symref.i_Index]; - if (v == null) - stackframe.LocalScope[symref.i_Index] = v = DynValue.NewNil(); + DynValue currentValue = stackframe.LocalScope[symref.i_Index]; + if (currentValue == null) + { + if (isOmittedArgumentInFunctionCall && symref.i_Name == WellKnownSymbols.VARARGS) + { + stackframe.LocalScope[symref.i_Index] = DynValue.Void; + return; + } + else + { + stackframe.LocalScope[symref.i_Index] = currentValue = DynValue.NewNil(); + } + } - v.Assign(value); + currentValue.Assign(value); } private void ExecStoreLcl(Instruction i) @@ -642,7 +652,7 @@ private void ExecArgs(Instruction I) { if (i >= argsList.Count) { - this.AssignLocal(I.SymbolList[i], DynValue.NewNil()); + this.AssignLocal(I.SymbolList[i], DynValue.NewNil(), isOmittedArgumentInFunctionCall: true); } else if ((i == I.SymbolList.Length - 1) && (I.SymbolList[i].i_Name == WellKnownSymbols.VARARGS)) {