daniellansun commented on code in PR #2784: URL: https://github.com/apache/groovy/pull/2784#discussion_r3785708002
########## src/test/groovy/org/codehaus/groovy/classgen/asm/SwitchExpressionBytecodeTest.groovy: ########## @@ -0,0 +1,143 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.codehaus.groovy.classgen.asm + +import org.junit.jupiter.api.Test + +/** + * GROOVY-12255: bytecode shape of first-class switch expressions — no closure + * wrapper, and tableswitch / lookupswitch when the selector and case labels + * permit it. + */ +final class SwitchExpressionBytecodeTest extends AbstractBytecodeTestCase { + + @Test + void noClosureAllocationForSwitchExpression() { + def bytecode = compile(method: 'run', '''\ + def r = switch (1) { + case 1 -> 'a' + default -> 'z' + } + ''') + assert !bytecode.hasStrictSequence(['INVOKESPECIAL', 'org/codehaus/groovy/runtime/callsite']) + assert !bytecode.toString().contains('InnerClassNode') + assert !bytecode.toString().contains('$_run_closure') Review Comment: The test now compiles a real `{ -> … }` closure first and asserts that `$_run_closure` is present, then compiles the switch expression and asserts that the same marker is absent. The indy/callsite check is gone. `InnerClassNode` is only asserted if the closure probe actually emits it. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
