Test nested record matching, thankfully switch does the heavy lifting, fixes #349
Some checks failed
Build and Test with Maven / Build-and-test-with-Maven (push) Failing after 42s

This commit is contained in:
Daniel Holle 2024-11-20 13:17:10 +01:00
parent ff715a22cf
commit 443b8b0c09
2 changed files with 41 additions and 1 deletions

View File

@ -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;
}
}

View File

@ -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 {