From adfe452e319b448fec5bf9986b5dc5af4b6f98dd Mon Sep 17 00:00:00 2001
From: Pieter12345
Date: Wed, 25 Dec 2024 04:48:53 +0100
Subject: [PATCH] Fix procedure as argument in sprintf() and lsprintf() not
resolving
Fix procedure as second and third argument in `sprintf()` and `lsprintf()` respectively causing a compile error when trying to resolve the procedure during optimization.
Fixes:
```
:proc _a() { return 123; } msg(sprintf('%x', _a()));
COMPILE ERROR: The function "_a" does not exist in the Java Interpreter
at :Interpreter:1.45
```
---
src/main/java/com/laytonsmith/core/functions/StringHandling.java | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/main/java/com/laytonsmith/core/functions/StringHandling.java b/src/main/java/com/laytonsmith/core/functions/StringHandling.java
index 3f2413f58..153340bf5 100644
--- a/src/main/java/com/laytonsmith/core/functions/StringHandling.java
+++ b/src/main/java/com/laytonsmith/core/functions/StringHandling.java
@@ -1623,6 +1623,7 @@ public ParseTree optimizeDynamic(Target t, Environment env,
me.setChildren(children);
me.setOptimized(true); //After this run, we will be, anyways.
if(children.size() == 3 && children.get(2).getData() instanceof CFunction
+ && ((CFunction) children.get(2).getData()).hasFunction()
&& ((CFunction) children.get(2).getData()).getFunction().getName().equals(array.NAME)) {
//Normally we can't do anything with a hardcoded array, it's considered dynamic. But in this case, we can at least pull up the arguments,
//because the array's size is constant, even if the arguments in it aren't.