This is an automated email from the ASF dual-hosted git repository. joshtynjala pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/royale-compiler.git
commit ced2dde291e5e578ab357ac7d4176ff145238f3c Author: Josh Tynjala <[email protected]> AuthorDate: Thu Oct 27 14:20:29 2022 -0700 SwitchNode: fix getDefaultNode() failing to get default node from inside an IBlockNode --- .../java/org/apache/royale/compiler/utils/ASNodeUtils.java | 1 - .../apache/royale/compiler/internal/tree/as/SwitchNode.java | 13 +++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/utils/ASNodeUtils.java b/compiler-jx/src/main/java/org/apache/royale/compiler/utils/ASNodeUtils.java index b2ea9a64c..ea3ec09cf 100644 --- a/compiler-jx/src/main/java/org/apache/royale/compiler/utils/ASNodeUtils.java +++ b/compiler-jx/src/main/java/org/apache/royale/compiler/utils/ASNodeUtils.java @@ -51,7 +51,6 @@ public class ASNodeUtils return retVal.toArray(new IConditionalNode[0]); } - // there seems to be a bug in the ISwitchNode.getDefaultNode(), need to file a bug public static final ITerminalNode getDefaultNode(ISwitchNode node) { IBlockNode block = (IBlockNode) node.getChild(1); diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/SwitchNode.java b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/SwitchNode.java index daf21ea2f..226146c88 100644 --- a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/SwitchNode.java +++ b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/SwitchNode.java @@ -24,6 +24,7 @@ import java.util.ArrayList; import org.apache.royale.compiler.parsing.IASToken; import org.apache.royale.compiler.tree.ASTNodeID; import org.apache.royale.compiler.tree.as.IASNode; +import org.apache.royale.compiler.tree.as.IBlockNode; import org.apache.royale.compiler.tree.as.IConditionalNode; import org.apache.royale.compiler.tree.as.IExpressionNode; import org.apache.royale.compiler.tree.as.ISwitchNode; @@ -94,12 +95,20 @@ public class SwitchNode extends ConditionalNode implements ISwitchNode @Override public ITerminalNode getDefaultNode() { - int childCount = getChildCount(); + IASNode possibleBlock = getChild(1); + if (!(possibleBlock instanceof IBlockNode)) + { + return null; + } + IBlockNode blockNode = (IBlockNode) possibleBlock; + int childCount = blockNode.getChildCount(); for (int i = childCount - 1; i >= 0; i--) { - IASNode child = getChild(i); + IASNode child = blockNode.getChild(i); if (child instanceof ITerminalNode) + { return (ITerminalNode)child; + } } return null;
