Skip to content

Commit 68222b0

Browse files
committed
Add test exercising static, virtual and interface lambdas
These compile down to direct references to a static, virtual and interface method (i.e. to method reference kinds REF_invokeStatic, REF_invokeVirtual and REF_invokeInterface as described at https://docs.oracle.com/javase/9/docs/api/java/lang/invoke/MethodHandleInfo.html)
1 parent 1ee70bd commit 68222b0

File tree

9 files changed

+54
-1
lines changed

9 files changed

+54
-1
lines changed
116 Bytes
Binary file not shown.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
interface IntToInt {
2+
public int f(int x);
3+
}
128 Bytes
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
interface OtherInterface {
2+
3+
int f(int x);
4+
5+
}
180 Bytes
Binary file not shown.
1.95 KB
Binary file not shown.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
public class Test implements OtherInterface {
2+
3+
public static int staticMethod(int x) { return x + 1; }
4+
5+
private int field = 1;
6+
7+
public int instanceMethod(int x) { return field + x; }
8+
9+
// Implement OtherInterface
10+
public int f(int x) { return x + 1; }
11+
12+
interface MakeTest {
13+
public Test makeTest();
14+
}
15+
16+
public static void main() {
17+
18+
IntToInt staticMethodBound = Test::staticMethod;
19+
Test instance = new Test();
20+
IntToInt instanceMethodBound = instance::instanceMethod;
21+
IntToInt interfaceMethodBound = ((OtherInterface)instance)::f;
22+
MakeTest makeTest = Test::new;
23+
24+
assert staticMethodBound.f(1) == 2;
25+
assert interfaceMethodBound.f(1) == 2;
26+
assert instanceMethodBound.f(1) == 2;
27+
assert makeTest.makeTest().instanceMethod(1) == 2;
28+
29+
}
30+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CORE
2+
Test
3+
--function Test.main
4+
^VERIFICATION SUCCESSFUL$
5+
line 24 assertion at file Test\.java line 24 function java::Test\.main:\(\)V bytecode-index 30: SUCCESS
6+
line 25 assertion at file Test\.java line 25 function java::Test\.main:\(\)V bytecode-index 41: SUCCESS
7+
line 26 assertion at file Test\.java line 26 function java::Test\.main:\(\)V bytecode-index 52: SUCCESS
8+
line 27 assertion at file Test\.java line 27 function java::Test\.main:\(\)V bytecode-index 64: SUCCESS
9+
^EXIT=0$
10+
^SIGNAL=0$
11+
--
12+
--
13+
This checks that the REF_invokeStatic, REF_invokeDynamic, REF_newInvokeSpecial and REF_invokeInterface method
14+
handles present in Test.class behave as intended. REF_invokeSpecial is used for the synthetic lambda methods
15+
(and private method calls), and is exercised in other lambda tests.

jbmc/src/java_bytecode/lambda_synthesis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ static optionalt<irep_idt> get_unique_abstract_method(
121121
}
122122
if(!ns.lookup(mangled_name).type.get_bool(ID_C_abstract))
123123
continue;
124-
if(result.has_value() && mangled_name != *result)
124+
if(result.has_value())
125125
{
126126
throw no_unique_unimplemented_method_exceptiont(
127127
"produces a type with at least two unimplemented methods");

0 commit comments

Comments
 (0)