diff a/test/jdk/jdk/incubator/code/TestSSACapture.java b/test/jdk/jdk/incubator/code/TestSSACapture.java --- /dev/null +++ b/test/jdk/jdk/incubator/code/TestSSACapture.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import jdk.incubator.code.CodeTransformer; +import jdk.incubator.code.Op; +import jdk.incubator.code.Reflect; +import jdk.incubator.code.dialect.core.CoreOp; +import jdk.incubator.code.dialect.core.SSA; +import jdk.incubator.code.dialect.java.JavaOp; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.lang.reflect.Method; +import java.util.Optional; +import java.util.function.IntSupplier; +import java.util.stream.Stream; + +/* + * @test + * @modules jdk.incubator.code + * @run junit TestSSACapture + */ + +public class TestSSACapture { + + @Reflect + static int lambda(int i) { + IntSupplier s = () -> i; + return s.getAsInt(); + } + + @Test + public void testLambda() { + CoreOp.FuncOp f = getFuncOp("lambda"); + CoreOp.FuncOp lf = f.transform(CodeTransformer.LOWERING_TRANSFORMER); + JavaOp.LambdaOp lop = (JavaOp.LambdaOp) lf.elements() + .filter(e -> e instanceof JavaOp.LambdaOp) + .findFirst().get(); + + Assertions.assertThrows(IllegalArgumentException.class, () -> SSA.transform(lop)); + } + + static CoreOp.FuncOp getFuncOp(String name) { + Optional om = Stream.of(TestSSACapture.class.getDeclaredMethods()) + .filter(m -> m.getName().equals(name)) + .findFirst(); + + Method m = om.get(); + return Op.ofMethod(m).get(); + } +}