You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2026/09/14 11:21:22 UTC
(groovy) 03/20: GROOVY-12399: address null handling review comment
This is an automated email from the ASF dual-hosted git repository.
paulk-asert pushed a commit to branch GROOVY_6_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 8596d6429d39913e3d6e8a9dcbaaa65d6fb2ced4
Author: Paul King <pa...@asert.com.au>
AuthorDate: Fri Sep 11 20:43:24 2026 +1000
GROOVY-12399: address null handling review comment
---
.../groovy/classgen/asm/SwitchExpressionWriter.java | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/SwitchExpressionWriter.java b/src/main/java/org/codehaus/groovy/classgen/asm/SwitchExpressionWriter.java
index 194ecfc7de..e3c3b9ef51 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/SwitchExpressionWriter.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/SwitchExpressionWriter.java
@@ -237,19 +237,17 @@ public class SwitchExpressionWriter {
}
/**
- * Completes the expression for an unmatched selector: {@code null} (cast
- * to the result type) for a switch in implicit-return position, otherwise
- * an {@code IllegalStateException} (GROOVY-12399).
+ * Completes the expression for an unmatched selector: {@code null} for a
+ * switch in implicit-return position, otherwise an
+ * {@code IllegalStateException} (GROOVY-12399).
*/
private void writeUnmatchedSelector(final SwitchExpression expression, final int selectorIndex, final ClassNode selectorType) {
if (unmatchedYieldsNull(expression)) {
- CompileStack.SwitchExpressionContext context = controller.getCompileStack().requireSwitchExpressionContext();
- OperandStack operandStack = controller.getOperandStack();
- controller.getMethodVisitor().visitInsn(ACONST_NULL);
- operandStack.push(ClassHelper.OBJECT_TYPE);
- operandStack.doGroovyCast(context.resultType);
- operandStack.remove(1);
- controller.getMethodVisitor().visitJumpInsn(GOTO, context.endLabel);
+ // the result type is always a reference type, so a plain null needs no
+ // cast; like `yield`, leave the operand stack model empty at the jump
+ MethodVisitor mv = controller.getMethodVisitor();
+ mv.visitInsn(ACONST_NULL);
+ mv.visitJumpInsn(GOTO, controller.getCompileStack().requireSwitchExpressionContext().endLabel);
} else {
throwUnmatchedSelector(selectorIndex, selectorType);
}