Skip to content

Commit a0d3a40

Browse files
committed
Fix parsing "(type) (val)" to execute()
1 parent 9a0782e commit a0d3a40

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/main/java/com/laytonsmith/core/functions/Compiler.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -639,18 +639,30 @@ private static void rewriteParenthesis(List<ParseTree> list) throws ConfigCompil
639639
for(int listInd = list.size() - 1; listInd >= 1; listInd--) {
640640
Stack<ParseTree> executes = new Stack<>();
641641
while(listInd > 0) {
642-
ParseTree lastNode = list.get(listInd);
642+
ParseTree node = list.get(listInd);
643643
try {
644-
if(lastNode.getData() instanceof CFunction cf
644+
if(node.getData() instanceof CFunction cf
645645
&& cf.hasFunction()
646646
&& cf.getFunction() != null
647647
&& cf.getFunction().getName().equals(Compiler.p.NAME)) {
648-
Mixed prevNode = list.get(listInd - 1).getData();
649-
if(prevNode instanceof CSymbol || prevNode instanceof CLabel || prevNode instanceof CString) {
650-
// It's just a parenthesis like @a = (1); or key: (value), so we should leave it alone.
648+
ParseTree prevNode = list.get(listInd - 1);
649+
Mixed prevNodeVal = prevNode.getData();
650+
651+
// Do not rewrite parenthesis like "@a = (1);" or "key: (value)" to execute().
652+
if(prevNodeVal instanceof CSymbol
653+
|| prevNodeVal instanceof CLabel || prevNodeVal instanceof CString) {
651654
break;
652655
}
653-
executes.push(lastNode);
656+
657+
// Do not rewrite casts to execute() if the callable is the cast (i.e. "(type) (val)").
658+
if(prevNodeVal instanceof CFunction cfunc && cfunc.hasFunction() && cfunc.getFunction() != null
659+
&& cfunc.getFunction().getName().equals(Compiler.p.NAME) && prevNode.numberOfChildren() == 1
660+
&& (prevNode.getChildAt(0).getData().isInstanceOf(CClassType.TYPE)
661+
|| __type_ref__.createFromBareStringOrConcats(prevNode.getChildAt(0)) != null)) {
662+
break;
663+
}
664+
665+
executes.push(node);
654666
list.remove(listInd--);
655667
} else {
656668
break;

0 commit comments

Comments
 (0)