Compare commits

...
Author SHA1 Message Date
dholle f66499b4fe Revert "Update"
SonarQube Scan / SonarQube Trigger (push) Failing after 3m27s
This reverts commit eb05d22735.
2026-09-29 18:01:44 +02:00
4 changed files with 10 additions and 54 deletions
-8
View File
@@ -1,8 +0,0 @@
sealed interface Interface permits A, B {}
public record A() implements Interface {}
public record B() implements Interface {}
public interface Matcher {
default match(A()@a) { return 0; }
default match(B()@b) { return 1; }
}
@@ -1,12 +0,0 @@
import java.lang.Integer;
import Matcher;
import Interface;
public class M implements Matcher {}
public class PatternMatchingInterface {
public static match(matcher, v) {
return matcher.match(v);
}
}
@@ -616,7 +616,7 @@ public class ASTToTargetAST {
}
}
private static TargetExpression generateCall(TargetMethod method, List<TargetLocalVar> params, TargetType classType, boolean isInterface) {
private static TargetExpression generateCall(TargetMethod method, List<TargetLocalVar> params, TargetType classType) {
var mParams = new ArrayList<TargetExpression>();
for (var i = 0; i < params.size(); i++) {
var tpe = method.signature().parameters().get(i).pattern().type();
@@ -624,11 +624,11 @@ public class ASTToTargetAST {
}
TargetExpression caseBody = new TargetMethodCall(
method.signature().returnType(),
method.isStatic() ? new TargetClassName(classType) : new TargetThis(classType),
new TargetThis(classType),
mParams,
classType,
method.name(),
method.isStatic(), isInterface, method.isPrivate()
false, false, method.isPrivate()
);
if (method.signature().returnType() != null) {
caseBody = new TargetReturn(caseBody);
@@ -636,11 +636,11 @@ public class ASTToTargetAST {
return caseBody;
}
private TargetExpression generatePatternOverloadsRec(int offset, TargetExpression switchExpr, List<TargetLocalVar> params, List<TargetPattern> patterns, List<TargetMethod> methods, TargetType classType, boolean isInterface) {
private TargetExpression generatePatternOverloadsRec(int offset, TargetExpression switchExpr, List<TargetLocalVar> params, List<TargetPattern> patterns, List<TargetMethod> methods, TargetType classType) {
if (methods.isEmpty()) throw new DebugException("Couldn't find a candidate for switch overloading");
if (methods.size() == 1) {
var method = methods.getFirst();
return generateCall(method, params, classType, isInterface);
return generateCall(method, params, classType);
}
var cases = new ArrayList<TargetSwitch.Case>();
@@ -689,11 +689,11 @@ public class ASTToTargetAST {
}).toList();
if (candidates.isEmpty()) {
var body = new TargetBlock(List.of(generateCall(method, params, classType, isInterface)));
var body = new TargetBlock(List.of(generateCall(method, params, classType)));
cases.add(new TargetSwitch.Case(List.of(lastPattern), body));
} else {
//candidates.forEach(m -> Target.logger.info(m.getSignature()));
var caseBody = generatePatternOverloadsRec(offset + 1, expr, params, patternsRec, candidates, classType, isInterface);
var caseBody = generatePatternOverloadsRec(offset + 1, expr, params, patternsRec, candidates, classType);
var body = new TargetBlock(List.of(caseBody));
var case_ = new TargetSwitch.Case(List.of(lastPattern), body);
@@ -746,7 +746,7 @@ public class ASTToTargetAST {
private Optional<TargetMethod> generateBridgeMethod(ClassOrInterface clazz, List<TargetMethod> methods) {
// If there's only one method we don't need a bridge
//if (clazz.isInterface()) return Optional.empty();
if (clazz.isInterface()) return Optional.empty();
if (methods.size() <= 1) return Optional.empty();
var firstMethod = methods.getFirst();
@@ -785,7 +785,7 @@ public class ASTToTargetAST {
var parameters = resParams.stream().map( p -> new TargetLocalVar(p.pattern().type(), p.pattern().name())).toList();
var classType = new TargetRefType(clazz.getClassName().toString());
var stmt = generatePatternOverloadsRec(0, new TargetLocalVar(resParams.getFirst().pattern().type(), resParams.getFirst().pattern().name()), parameters, List.of(), methods, classType, clazz.isInterface());
var stmt = generatePatternOverloadsRec(0, new TargetLocalVar(resParams.getFirst().pattern().type(), resParams.getFirst().pattern().name()), parameters, List.of(), methods, classType);
var block = new TargetBlock(List.of(stmt));
var generics = new HashSet<>(firstMethod.signature().generics());
@@ -868,7 +868,7 @@ public class ASTToTargetAST {
// Generate dispatch method
var classType = new TargetRefType(clazz.getClassName().toString());
var stmt = generatePatternOverloadsRec(0, new TargetLocalVar(signatureParams.getFirst().pattern().type(), signatureParams.getFirst().pattern().name()), parameters, List.of(), res, classType, clazz.isInterface());
var stmt = generatePatternOverloadsRec(0, new TargetLocalVar(signatureParams.getFirst().pattern().type(), signatureParams.getFirst().pattern().name()), parameters, List.of(), res, classType);
var block = new TargetBlock(List.of(stmt));
var bridgeMethod = new TargetMethod(firstMethod.access(), firstMethod.name(), block, group.signature.java, group.signature.tx, firstMethod.base(), null);
-24
View File
@@ -1081,30 +1081,6 @@ public class TestComplete {
assertEquals(40.0, m.invoke(instance, d, 0));
}
@Test
public void testPatternMatchingInterface() throws Exception {
ConsoleInterface.logLevel = LogLevel.INFO;
var classFiles = generateClassFiles(createClassLoader(), false, "Matcher.jav", "PatternMatchingInterface.jav");
var Intf = classFiles.get("Interface");
var clazz = classFiles.get("PatternMatchingInterface");
var M = classFiles.get("M");
var Matcher = classFiles.get("Matcher");
var a = classFiles.get("A").getDeclaredConstructor().newInstance();
var b = classFiles.get("B").getDeclaredConstructor().newInstance();
//var match = clazz.getDeclaredMethod("match", Intf);
//assertEquals(0, match.invoke(null, a));
//assertEquals(1, match.invoke(null, b));
var matcher = M.getDeclaredConstructor().newInstance();
var match2 = clazz.getDeclaredMethod("match", Matcher, Intf);
assertEquals(0, match2.invoke(null, matcher, a));
assertEquals(1, match2.invoke(null, matcher, b));
}
@Test
public void testInterfaces() throws Exception {
var classFiles = generateClassFiles(createClassLoader(), "Interfaces.jav");