Filter out duplicate patterns
Some checks failed
Build and Test with Maven / Build-and-test-with-Maven (push) Failing after 43s

This commit is contained in:
Daniel Holle 2024-11-20 11:37:50 +01:00
parent 170955b333
commit ff715a22cf

View File

@ -343,6 +343,8 @@ public class ASTToTargetAST {
}
var cases = new ArrayList<TargetSwitch.Case>();
var usedPatterns = new HashSet<TargetPattern>();
for (var method : methods) {
var patternsRec = new ArrayList<>(patterns);
@ -363,6 +365,10 @@ public class ASTToTargetAST {
}
}
var lastPattern = patternsRec.getLast();
if (usedPatterns.contains(lastPattern)) continue;
usedPatterns.add(lastPattern);
var candidates = methods.stream().filter(m -> {
var j = 0;
for (var param : m.signature().parameters()) {
@ -377,7 +383,7 @@ public class ASTToTargetAST {
var caseBody = generatePatternOverloadsRec(offset + 1, expr, params, patternsRec, candidates, classType);
var body = new TargetBlock(List.of(caseBody));
var case_ = new TargetSwitch.Case(List.of(patternsRec.getLast()), body);
var case_ = new TargetSwitch.Case(List.of(lastPattern), body);
cases.add(case_);
}