From d0d9c46a67deca817ea508eac1469aa71aa072c9 Mon Sep 17 00:00:00 2001 From: Daniel Holle Date: Wed, 4 Dec 2024 12:22:26 +0100 Subject: [PATCH] Work on constraints for parameters of generic records --- .../typeinference/typeAlgo/TYPE.java | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java index f7f0c7bf..02e4801d 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java @@ -101,33 +101,27 @@ public class TYPE { public ConstraintSet addRecursiveParameterConstraints(RecordPattern recordPattern, TypeInferenceBlockInformation blockInformation){ ConstraintSet constraintSet = new ConstraintSet(); - System.out.println("TEST"); var subPatternList = recordPattern.getSubPattern(); + var resolver = new GenericsResolverSameName(); int counter = 0; - for(Pattern el : subPatternList){ - - if(el instanceof RecordPattern){ + for (Pattern el : subPatternList){ + if (el instanceof RecordPattern){ constraintSet.addAll(addRecursiveParameterConstraints((RecordPattern) el, blockInformation)); - }else if (recordPattern.getType() instanceof RefType refType){ + } else if (recordPattern.getType() instanceof RefType refType){ var allClasses = blockInformation.getAvailableClasses(); - RefTypeOrTPHOrWildcardOrGeneric type; var typename = refType.getName().getClassName(); 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(), receiverType == null ? type : receiverType, PairOperator.SMALLERDOT, new SourceLoc(blockInformation.getCurrentClass().getFileName(), el.getOffset().getLine()))); + var fieldCons = new Pair(el.getType(), assumption.getType(resolver), PairOperator.SMALLERDOT); + var recvCons = new Pair(refType, assumption.getReceiverType(resolver), PairOperator.EQUALSDOT); + constraintSet.addUndConstraint(fieldCons); + constraintSet.addUndConstraint(recvCons); } }