Skip to content

Commit

Permalink
Merge pull request #134 from stuartwdouglas/gizmo-return
Browse files Browse the repository at this point in the history
Fix gizmp return type issue
  • Loading branch information
mkouba authored Nov 23, 2018
2 parents 92e2e28 + b5ecb8d commit f0bcd03
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -772,13 +772,13 @@ public void writeBytecode(MethodVisitor methodVisitor) {
methodVisitor.visitInsn(Opcodes.RETURN);
} else {
loadResultHandle(methodVisitor, resolvedReturnValue, BytecodeCreatorImpl.this, methodDescriptor.getReturnType());
if (resolvedReturnValue.getType().equals("S") || resolvedReturnValue.getType().equals("Z") || resolvedReturnValue.getType().equals("I") || resolvedReturnValue.getType().equals("B")) {
if (methodDescriptor.getReturnType().equals("S") || methodDescriptor.getReturnType().equals("Z") || methodDescriptor.getReturnType().equals("I") || methodDescriptor.getReturnType().equals("B")) {
methodVisitor.visitInsn(Opcodes.IRETURN);
} else if (resolvedReturnValue.getType().equals("J")) {
} else if (methodDescriptor.getReturnType().equals("J")) {
methodVisitor.visitInsn(Opcodes.LRETURN);
} else if (resolvedReturnValue.getType().equals("F")) {
} else if (methodDescriptor.getReturnType().equals("F")) {
methodVisitor.visitInsn(Opcodes.FRETURN);
} else if (resolvedReturnValue.getType().equals("D")) {
} else if (methodDescriptor.getReturnType().equals("D")) {
methodVisitor.visitInsn(Opcodes.DRETURN);
} else {
methodVisitor.visitInsn(Opcodes.ARETURN);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2018 Red Hat, Inc.
*
* Licensed 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.jboss.protean.gizmo;

import org.junit.Test;
import org.objectweb.asm.Opcodes;

public class PrimitiveReturnTypeTestCase {

@Test
public void testPrimitiveReturnType() throws Exception {
TestClassLoader cl = new TestClassLoader(getClass().getClassLoader());
try (ClassCreator creator = ClassCreator.builder().classOutput(cl).className("com.MyTest").build()) {
MethodCreator method = creator.getMethodCreator("transform", Object.class).setModifiers(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC);
ResultHandle ret = method.readStaticField(FieldDescriptor.of(Integer.class, "MAX_VALUE", int.class));
method.returnValue(ret);
}
Class<?> clazz = cl.loadClass("com.MyTest");
clazz.getMethod("transform").invoke(null);
}
}

0 comments on commit f0bcd03

Please sign in to comment.