Skip to content

Commit 70f9729

Browse files
committed
Java frontend: handle lambdas that adapt a method with a return type to an interface method returning void
1 parent dbe56e7 commit 70f9729

File tree

7 files changed

+41
-1
lines changed

7 files changed

+41
-1
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
public class Test {
2+
3+
public int lastArgument = 0;
4+
public int intToInt(int x) { lastArgument = x; return x + 1; }
5+
public Integer intToInteger(int x) { lastArgument = x; return x + 1; }
6+
public Object intToObject(int x) { lastArgument = x; return -1; }
7+
8+
public interface IntToVoid {
9+
void consume(int x);
10+
}
11+
12+
public static void test() {
13+
Test t = new Test();
14+
15+
IntToVoid intToVoid = t::intToInt;
16+
intToVoid.consume(5);
17+
assert t.lastArgument == 5;
18+
19+
IntToVoid intToVoid2 = t::intToInteger;
20+
intToVoid2.consume(10);
21+
assert t.lastArgument == 10;
22+
23+
IntToVoid intToVoid3 = t::intToObject;
24+
intToVoid3.consume(15);
25+
assert t.lastArgument == 15;
26+
27+
assert false; // Check we got here
28+
29+
}
30+
31+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
Test
3+
--function Test.test --classpath `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar`
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
\[java::Test\.test:\(\)V\.assertion\.1\] line 17 assertion at file Test\.java line 17 function java::Test\.test:\(\)V bytecode-index 22: SUCCESS
7+
\[java::Test\.test:\(\)V\.assertion\.2\] line 21 assertion at file Test\.java line 21 function java::Test\.test:\(\)V bytecode-index 41: SUCCESS
8+
\[java::Test\.test:\(\)V\.assertion\.3\] line 25 assertion at file Test\.java line 25 function java::Test\.test:\(\)V bytecode-index 60: SUCCESS
9+
\[java::Test\.test:\(\)V\.assertion\.4\] line 27 assertion at file Test\.java line 27 function java::Test\.test:\(\)V bytecode-index 66: FAILURE

jbmc/src/java_bytecode/lambda_synthesis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ codet invokedynamic_synthetic_method(
806806
"param" + std::to_string(i));
807807
}
808808

809-
if(callee_return_type != empty_typet() && !is_constructor_lambda)
809+
if(function_type.return_type() != empty_typet() && !is_constructor_lambda)
810810
{
811811
symbol_exprt result_local = create_and_declare_local(
812812
function_id, "return_value", callee_return_type, symbol_table, result);

0 commit comments

Comments
 (0)