diff --git a/monticore-grammar/src/main/java/de/monticore/types/check/SymTypeOfIntersection.java b/monticore-grammar/src/main/java/de/monticore/types/check/SymTypeOfIntersection.java index 2d0b2f6dc2..953039d08d 100644 --- a/monticore-grammar/src/main/java/de/monticore/types/check/SymTypeOfIntersection.java +++ b/monticore-grammar/src/main/java/de/monticore/types/check/SymTypeOfIntersection.java @@ -3,12 +3,9 @@ import com.google.common.base.Preconditions; import de.monticore.types3.ISymTypeVisitor; +import de.monticore.types3.util.SymTypeExpressionComparator; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.Iterator; -import java.util.Set; -import java.util.Spliterator; +import java.util.*; import java.util.function.Consumer; import java.util.function.Predicate; import java.util.stream.Stream; @@ -22,7 +19,8 @@ public class SymTypeOfIntersection extends SymTypeExpression { public SymTypeOfIntersection(Collection types) { Preconditions.checkNotNull(types); - this.intersectedTypes = new LinkedHashSet<>(); + // TreeSet with comparator properly filters equal types + this.intersectedTypes = new TreeSet<>(new SymTypeExpressionComparator()); this.intersectedTypes.addAll(types); } diff --git a/monticore-grammar/src/main/java/de/monticore/types3/util/WithinTypeBasicSymbolsResolver.java b/monticore-grammar/src/main/java/de/monticore/types3/util/WithinTypeBasicSymbolsResolver.java index 7f005245dc..7a2cc85343 100644 --- a/monticore-grammar/src/main/java/de/monticore/types3/util/WithinTypeBasicSymbolsResolver.java +++ b/monticore-grammar/src/main/java/de/monticore/types3/util/WithinTypeBasicSymbolsResolver.java @@ -26,14 +26,7 @@ import de.monticore.types3.generics.TypeParameterRelations; import de.se_rwth.commons.logging.Log; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -101,19 +94,27 @@ protected Optional _resolveVariable( AccessModifier superModifier = private2Protected(accessModifier); List superTypes = getSuperTypes(thisType); resolvedSymType = Optional.empty(); + + // During OCL collection flattening, the same type is resolved twice for a field access of List, + // since List extends Collection (only valid in OCL). + // Thus, exactly equal types are filtered out. + Set resolvedTypes = new TreeSet<>(new SymTypeExpressionComparator()); for (SymTypeExpression superType : superTypes) { Optional resolvedInSuper = resolveVariable(superType, name, superModifier, predicate); - if (resolvedSymType.isPresent() && resolvedInSuper.isPresent()) { - Log.error("0xFD222 found variables with name \"" - + name + "\" in multiple super types of \"" - + thisType.printFullName() + "\""); + if (resolvedInSuper.isPresent()) { + resolvedTypes.add(resolvedInSuper.get()); } - else if (resolvedSymType.isEmpty() && resolvedInSuper.isPresent()) { - resolvedSymType = resolvedInSuper; - } - //filter based on local variables } + + if (resolvedTypes.size() > 1) { + Log.error("0xFD222 found variables with name \"" + + name + "\" in multiple super types of \"" + + thisType.printFullName() + "\""); + } else if (resolvedTypes.size() == 1) { + resolvedSymType = Optional.of(resolvedTypes.iterator().next()); + } + //filter based on local variables } // not expecting free type variables for fields,