Skip to content

Commit 900986e

Browse files
fix inline method returns with SafeScripts
1 parent c34f7ca commit 900986e

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

Code/ContextSystem/Contexts/MethodContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
namespace SER.Code.ContextSystem.Contexts;
2020

21-
public class MethodContext(MethodToken methodToken) : YieldingContext, IMayReturnValueContext
21+
public class MethodContext(MethodToken methodToken, bool yieldForSafety = true) : YieldingContext, IMayReturnValueContext
2222
{
2323
public readonly MethodArgumentDispatcher Dispatcher = new(methodToken.Method);
2424
public readonly Method Method = methodToken.Method;
@@ -68,7 +68,7 @@ protected override IEnumerator<float> Execute()
6868
{
6969
Log.Debug($"'{Method.Name}' method is now running..");
7070

71-
if (MainPlugin.Instance.Config?.SafeScripts is true)
71+
if (yieldForSafety && MainPlugin.Instance.Config?.SafeScripts is true)
7272
{
7373
yield return Timing.WaitForOneFrame;
7474
}

Code/ContextSystem/Contexts/ValueExpressionContext.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ public class MethodHandler : ValueExpressionContext.Handler
143143

144144
public MethodHandler(MethodToken token, bool allowsYielding, Script scr)
145145
{
146-
_context = new MethodContext(token)
146+
// Inline expressions are evaluated through IValueToken.Value(), which cannot resume after a yield.
147+
// Their methods must therefore execute immediately even when SafeScripts is enabled.
148+
_context = new MethodContext(token, yieldForSafety: allowsYielding)
147149
{
148150
Script = scr,
149151
LineNum = null

0 commit comments

Comments
 (0)