From 24bf3d350fb1024e4936dd7a68866cd0b99df3bc Mon Sep 17 00:00:00 2001 From: Ruben Date: Fri, 29 Nov 2024 13:50:09 +0100 Subject: [PATCH] feat: add Generic Resolver for Records --- .../dhbwstuttgart/typeinference/typeAlgo/TYPE.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java index 8aa68f07..f7f0c7bf 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java @@ -9,6 +9,7 @@ import de.dhbwstuttgart.syntaxtree.factory.ASTFactory; import de.dhbwstuttgart.syntaxtree.statement.Statement; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; +import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption; import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation; import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation; import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; @@ -100,6 +101,7 @@ public class TYPE { public ConstraintSet addRecursiveParameterConstraints(RecordPattern recordPattern, TypeInferenceBlockInformation blockInformation){ ConstraintSet constraintSet = new ConstraintSet(); + System.out.println("TEST"); var subPatternList = recordPattern.getSubPattern(); int counter = 0; @@ -115,8 +117,17 @@ public class TYPE { for (ClassOrInterface allClass : allClasses) { var className = allClass.getClassName().getClassName(); if(className.equals(typename)){ + + var resolver = new GenericsResolverSameName(); + + FormalParameter param = (FormalParameter) allClass.getConstructors().getFirst().getParameterList().getParameterAt(counter); + FieldAssumption assumption = new FieldAssumption(param.getName(), allClass, param.getType(), blockInformation.getCurrentTypeScope()); + + + RefTypeOrTPHOrWildcardOrGeneric receiverType = assumption.getReceiverType(resolver); + type = allClass.getConstructors().getFirst().getParameterList().getParameterAt(counter).getType(); - constraintSet.addUndConstraint(new Pair(el.getType(), type, PairOperator.SMALLERDOT, new SourceLoc(blockInformation.getCurrentClass().getFileName(), el.getOffset().getLine()))); + constraintSet.addUndConstraint(new Pair(el.getType(), receiverType == null ? type : receiverType, PairOperator.SMALLERDOT, new SourceLoc(blockInformation.getCurrentClass().getFileName(), el.getOffset().getLine()))); } }