diff --git a/resources/bytecode/javFiles/OverloadNestedPattern.jav b/resources/bytecode/javFiles/OverloadNestedPattern.jav new file mode 100644 index 00000000..77613284 --- /dev/null +++ b/resources/bytecode/javFiles/OverloadNestedPattern.jav @@ -0,0 +1,20 @@ +import java.lang.Object; +import java.lang.Integer; +import java.lang.Float; + +public record R(Object nested) {} + +public class OverloadNestedPattern { + + public Integer m(R(R(Integer a)), R(Integer b)) { + return 1; + } + + public Integer m(R(R(Float a)), R(Float b)) { + return 2; + } + + public Integer m(R(Integer a), R(Integer b)) { + return 3; + } +} \ No newline at end of file diff --git a/src/test/java/TestComplete.java b/src/test/java/TestComplete.java index ca18e748..0b1decb1 100644 --- a/src/test/java/TestComplete.java +++ b/src/test/java/TestComplete.java @@ -838,7 +838,6 @@ public class TestComplete { var instance = clazz.getDeclaredConstructor().newInstance(); } - @Ignore("Not implemented") @Test public void testOverloadPattern() throws Exception { var classFiles = generateClassFiles(new ByteArrayClassLoader(), "OverloadPattern.jav"); @@ -864,6 +863,27 @@ public class TestComplete { assertEquals(m3.invoke(instance, 10), 10); } + @Test + public void testOverloadNestedPattern() throws Exception { + var classFiles = generateClassFiles(new ByteArrayClassLoader(), "OverloadNestedPattern.jav"); + var clazz = classFiles.get("OverloadNestedPattern"); + var rec = classFiles.get("R"); + + var instance = clazz.getDeclaredConstructor().newInstance(); + var ctor = rec.getDeclaredConstructor(Object.class); + var r1 = ctor.newInstance(1); + var r2 = ctor.newInstance(r1); + + var m = clazz.getDeclaredMethod("m", rec, rec); + assertEquals(m.invoke(instance, r2, r1), 1); + + var r3 = ctor.newInstance(2f); + var r4 = ctor.newInstance(r3); + assertEquals(m.invoke(instance, r4, r3), 2); + + assertEquals(m.invoke(instance, r1, r1), 3); + } + //@Ignore("Not implemented") @Test public void testOverloadPatternMatching() throws Exception {