feat: further implementation
Some checks failed
Build and Test with Maven / Build-and-test-with-Maven (push) Failing after 7m5s

This commit is contained in:
Ruben 2024-08-02 18:02:35 +02:00
parent 139325e78f
commit cc8f36d3ec
3 changed files with 17 additions and 10 deletions

View File

@ -11,7 +11,6 @@ public class SwitchInfered {
public main(o) {
return switch (o) {
case Rec(a, b) -> a;
case Integer i -> i+1;
default -> 0;
};
}

View File

@ -843,8 +843,7 @@ public class TYPEStmt implements StatementVisitor {
}
if (label.getPattern() instanceof RecordPattern) {
RecordPattern recordPattern = (RecordPattern) label.getPattern();
System.out.println("HALFTAN DER WEI?E ICH CHECK ECHT GART NCIHTS MEHR");
System.out.println(recordPattern.getName());
//constraintsSet.addUndConstraint(new Pair(label.getPattern().getType(), switchStmt.getSwitch().getType(), PairOperator.SMALLERDOT, loc(label.getOffset())));
} else if (label.getPattern() instanceof FormalParameter) {
constraintsSet.addUndConstraint(new Pair(label.getPattern().getType(), switchStmt.getSwitch().getType(), PairOperator.SMALLERDOT, loc(label.getOffset())));
@ -862,7 +861,7 @@ public class TYPEStmt implements StatementVisitor {
if (el.getType() instanceof RefType) {
var recType = el;
if(el.getPattern() instanceof RecordPattern){
if (el.getPattern() instanceof RecordPattern) {
var pattern = (RecordPattern) recType.getPattern();
var allClasses = info.getAvailableClasses();
@ -870,13 +869,22 @@ public class TYPEStmt implements StatementVisitor {
var test = "";
for(int i = 0; i < pattern.getSubPattern().size(); i++){
var constructors = interestingClasses.get(0).getConstructors();
for (int i = 0; i < pattern.getSubPattern().size(); i++) {
var supPattern = pattern.getSubPattern().get(i);
for(int j = 0; j < interestingClasses.size(); j++){
constraintsSet.addUndConstraint(new Pair(supPattern.getType(), interestingClasses.get(j).getFieldDecl().get(i).getType(), PairOperator.SMALLERDOT, loc(switchStmt.getOffset())));
}
for (int j = 0; j < interestingClasses.size(); j++) {
var clazz = interestingClasses.get(j);
for (int k = 0; k < clazz.getConstructors().size(); k++) {
var constructor = clazz.getConstructors().get(k);
//Erster Constraint wahrscheinlich unnötig.
constraintsSet.addUndConstraint(new Pair( clazz.getFieldDecl().get(i).getType(), constructor.getParameterList().getParameterAt(i).getType(), PairOperator.SMALLERDOT, loc(constructor.getParameterList().getParameterAt(i).getOffset())));
constraintsSet.addUndConstraint(new Pair(supPattern.getType(), constructor.getParameterList().getParameterAt(i).getType(), PairOperator.SMALLERDOT, loc(constructor.getParameterList().getParameterAt(i).getOffset())));
}
}
}
}

View File

@ -687,10 +687,10 @@ public class TestComplete {
var record = classFiles.get("Rec");
var ctor = record.getDeclaredConstructor(Object.class, Object.class);
var r1 = ctor.newInstance(1, 1);
var r1 = ctor.newInstance("asd", "asb");
assertEquals(swtch.invoke(instance, r1), 1);
assertEquals(swtch.invoke(instance, r1), "asd");
}
@Ignore("Not implemented")