Fix wrong type conversion, see #297
All checks were successful
Build and Test with Maven / Build-and-test-with-Maven (push) Successful in 2m51s

This commit is contained in:
Daniel Holle 2024-03-18 12:14:03 +01:00
parent 01e374eadd
commit c07d4d36e9
3 changed files with 20 additions and 1 deletions

View File

@ -0,0 +1,11 @@
import java.lang.Integer;
public class Bug297 {
public static operation(func, a, b) {
return func.apply(a, b);
}
public exec() {
return Foo.operation((x, y) -> x + y, 10, 10);
}
}

View File

@ -966,8 +966,8 @@ public class Codegen {
state.contextType = state.returnType; state.contextType = state.returnType;
generate(state, ret.expression()); generate(state, ret.expression());
state.contextType = ctype; state.contextType = ctype;
boxPrimitive(state, ret.expression().type());
convertTo(state, ret.expression().type(), state.returnType); convertTo(state, ret.expression().type(), state.returnType);
boxPrimitive(state, state.returnType);
mv.visitInsn(ARETURN); mv.visitInsn(ARETURN);
} else } else
mv.visitInsn(RETURN); mv.visitInsn(RETURN);

View File

@ -947,4 +947,12 @@ public class TestComplete {
var clazz = classFiles.get("Bug296"); var clazz = classFiles.get("Bug296");
clazz.getDeclaredMethod("m1").invoke(null); clazz.getDeclaredMethod("m1").invoke(null);
} }
@Test
public void testBug297() throws Exception {
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Bug297.jav");
var clazz = classFiles.get("Bug297");
var instance = clazz.getDeclaredConstructor().newInstance();
clazz.getDeclaredMethod("exec").invoke(instance);
}
} }