Skip to content

Commit 6daa69d

Browse files
committed
Fixed calling subroutines inside subroutines sometimes throwing an exception. Fixed subroutine IndexAssigner issue. Fixed returning values recursively.
1 parent d29c514 commit 6daa69d

3 files changed

Lines changed: 5 additions & 3 deletions

File tree

Deltinteger/Deltinteger/Parse/Functions/DefinedMethod.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ public void SetupSubroutine()
340340

341341
// Setup the return handler.
342342
ReturnHandler returnHandler = new ReturnHandler(subroutineRule.ActionSet, Name, multiplePaths);
343-
ActionSet actionSet = subroutineRule.ActionSet.New(returnHandler);
343+
ActionSet actionSet = subroutineRule.ActionSet.New(returnHandler).New(subroutineRule.ActionSet.IndexAssigner.CreateContained());
344344

345345
// Get the variables that will be used to store the parameters.
346346
IndexReference[] parameterStores = new IndexReference[ParameterVars.Length];
@@ -371,6 +371,8 @@ public void SetupSubroutine()
371371
// Calls single-instance methods.
372372
private IWorkshopTree ParseSubroutine(ActionSet actionSet, MethodCall methodCall)
373373
{
374+
if (subroutineInfo == null) SetupSubroutine();
375+
374376
for (int i = 0; i < subroutineInfo.ParameterStores.Length; i++)
375377
actionSet.AddAction(subroutineInfo.ParameterStores[i].SetVariable((Element)methodCall.ParameterValues[i]));
376378

Deltinteger/Deltinteger/Parse/Functions/RecursiveStack.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private IWorkshopTree ParseCall(ActionSet actionSet, MethodCall methodCall)
4949
continueAt.SetSkipCount((Element)nextContinue.GetVariable());
5050
actionSet.AddAction(continueAt);
5151

52-
method.block.Translate(actionSet);
52+
method.block.Translate(actionSet.New(returnHandler));
5353

5454
PopParameterStacks(actionSet);
5555

Deltinteger/Deltinteger/Parse/Functions/ReturnHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public RuleReturnHandler(ActionSet actionSet) : base(actionSet, null, false) {}
7575

7676
public override void ApplyReturnSkips() => throw new Exception("Can't apply return skips in a rule.");
7777
public override IWorkshopTree GetReturnedValue() => throw new Exception("Can't get the returned value of a rule.");
78-
public override void ReturnValue(IWorkshopTree value) => throw new Exception("Can't return a value in a rule..");
78+
public override void ReturnValue(IWorkshopTree value) => throw new Exception("Can't return a value in a rule.");
7979

8080
public override void Return()
8181
{

0 commit comments

Comments
 (0)