From 4318856fa83326826fe43fd033c2b55e4bb5d259 Mon Sep 17 00:00:00 2001 From: Daniel Holle Date: Thu, 12 Dec 2024 14:21:23 +0100 Subject: [PATCH] Fix lookup --- .../typeinference/typeAlgo/TYPE.java | 37 +++++++++---------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java index 5b38591a..7c852466 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java @@ -103,34 +103,31 @@ public class TYPE { var subPatternList = recordPattern.getSubPattern(); var resolver = new GenericsResolverSameName(); + var refType = (RefType) recordPattern.getType(); + + var allClasses = blockInformation.getAvailableClasses(); + var typename = refType.getName().getClassName(); + + ClassOrInterface allClass = allClasses.stream().filter(c -> c.getClassName().getClassName().equals(typename)).findFirst().orElseThrow(); int counter = 0; for (Pattern el : subPatternList){ if (el instanceof RecordPattern){ constraintSet.addAll(addRecursiveParameterConstraints((RecordPattern) el, blockInformation)); - } else if (recordPattern.getType() instanceof RefType refType){ - var allClasses = blockInformation.getAvailableClasses(); - var typename = refType.getName().getClassName(); + } else { + FormalParameter param = (FormalParameter) allClass.getConstructors().getFirst().getParameterList().getParameterAt(counter); + FieldAssumption assumption = new FieldAssumption(param.getName(), allClass, param.getType(), blockInformation.getCurrentTypeScope()); - for (ClassOrInterface allClass : allClasses) { - var className = allClass.getClassName().getClassName(); - if(className.equals(typename)){ - FormalParameter param = (FormalParameter) allClass.getConstructors().getFirst().getParameterList().getParameterAt(counter); - FieldAssumption assumption = new FieldAssumption(param.getName(), allClass, param.getType(), blockInformation.getCurrentTypeScope()); + 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); - 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); - - for (var i = 0; i < refType.getParaList().size(); i++) { - constraintSet.addUndConstraint(new Pair(refType.getParaList().get(i), - ((RefType)assumption.getReceiverType(resolver)).getParaList().get(i), - PairOperator.EQUALSDOT)); - } - } + for (var i = 0; i < refType.getParaList().size(); i++) { + constraintSet.addUndConstraint(new Pair(refType.getParaList().get(i), + ((RefType)assumption.getReceiverType(resolver)).getParaList().get(i), + PairOperator.EQUALSDOT)); } - } counter++; }