Skip to content

Commit

Permalink
Add check for CClosure
Browse files Browse the repository at this point in the history
  • Loading branch information
Anatoliy057 committed Apr 3, 2024
1 parent 606e6d2 commit 52426c6
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/main/java/com/laytonsmith/core/functions/Regex.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.laytonsmith.core.ParseTree;
import com.laytonsmith.core.compiler.FileOptions;
import com.laytonsmith.core.constructs.CArray;
import com.laytonsmith.core.constructs.CClosure;
import com.laytonsmith.core.constructs.CFunction;
import com.laytonsmith.core.constructs.CInt;
import com.laytonsmith.core.constructs.CString;
Expand Down Expand Up @@ -298,10 +299,12 @@ public ParseTree optimizeDynamic(Target t, Environment env,
List<ParseTree> children, FileOptions fileOptions)
throws ConfigCompileException, ConfigRuntimeException {
ParseTree patternArg = children.get(0);
Mixed patternData = patternArg.getData();
ParseTree replacementArg = children.get(1);
if(!Construct.IsDynamicHelper(patternArg.getData()) && !Construct.IsDynamicHelper(replacementArg.getData())) {
String pattern = patternArg.getData().val();
String replacement = replacementArg.getData().val();
Mixed replacementData = replacementArg.getData();
if(!Construct.IsDynamicHelper(patternData) && !(replacementData instanceof CClosure) && !Construct.IsDynamicHelper(replacementData)) {
String pattern = patternData.val();
String replacement = replacementData.val();
if(isLiteralRegex(pattern) && !isBackreference(replacement)) {
//We want to replace this with replace()
//Note the alternative order of arguments
Expand Down

0 comments on commit 52426c6

Please sign in to comment.