Skip to content

Commit

Permalink
fix handling type vars of composed methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mmews committed Apr 16, 2024
1 parent f6275f2 commit ab30bd7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
package org.eclipse.n4js.scoping.members;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand All @@ -24,15 +26,18 @@
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.n4js.scoping.members.ComposedMemberInfoBuilder.ToBeComposedMemberInfo;
import org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef;
import org.eclipse.n4js.ts.typeRefs.TypeRef;
import org.eclipse.n4js.ts.typeRefs.UnknownTypeRef;
import org.eclipse.n4js.ts.types.GenericType;
import org.eclipse.n4js.ts.types.MemberAccessModifier;
import org.eclipse.n4js.ts.types.MemberType;
import org.eclipse.n4js.ts.types.TField;
import org.eclipse.n4js.ts.types.TFormalParameter;
import org.eclipse.n4js.ts.types.TMember;
import org.eclipse.n4js.ts.types.TMethod;
import org.eclipse.n4js.ts.types.TSetter;
import org.eclipse.n4js.ts.types.TypeVariable;
import org.eclipse.n4js.ts.types.VoidType;
import org.eclipse.n4js.types.utils.TypeUtils;
import org.eclipse.n4js.typesystem.N4JSTypeSystem;
Expand Down Expand Up @@ -85,13 +90,14 @@ public class ComposedMemberInfo {
private final boolean hasValidationProblem = false;
private MemberAccessModifier accessibilityMin = MemberAccessModifier.PUBLIC;
private MemberAccessModifier accessibilityMax = MemberAccessModifier.PRIVATE;
private final Map<TypeVariable, TypeVariable> memberTypeVars = new LinkedHashMap<>();
private final Multimap<MemberType, TypeRef> typeRefsMap = LinkedHashMultimap.create();
private final List<TypeRef> typeRefs = new ArrayList<>();
private final List<TypeRef> methodTypeRefsVoid = new ArrayList<>();
private final List<TypeRef> methodTypeRefsNonVoid = new ArrayList<>();
private final Map<TypeRef, RuleEnvironment> typeRef2G = new HashMap<>();

private final List<ComposedFParInfo> fParameters = new ArrayList<>();

private boolean isVariadicButLastFParIsDifferent = false;

/**
Expand Down Expand Up @@ -174,6 +180,7 @@ synchronized private void initMemberAggregate() {
RuleEnvironment G = toBeComposedMemberInfo.G;
boolean structFieldInitMode = toBeComposedMemberInfo.structFieldInitMode;

handleTypeVars(member, G);
lastMType = handleMemberTypes(lastMType, member, structFieldInitMode);
handleReadOnlyField(member);
handleAccessibility(member);
Expand Down Expand Up @@ -266,6 +273,18 @@ private void handleAccessibility(TMember member) {
accessibilityMin = currAccessibility;
}

private void handleTypeVars(TMember member, RuleEnvironment G) {
if (member instanceof GenericType) {
GenericType method = (GenericType) member;
for (TypeVariable tv : method.getTypeVars()) {
TypeVariable tvCopy = TypeUtils.copyIfContained(tv);
ParameterizedTypeRef tvCopyTRef = TypeUtils.createTypeRef(tvCopy);
G.put(tv, tvCopyTRef);
memberTypeVars.put(tv, tvCopy);
}
}
}

private void handleTypeRefLists(TMember member, RuleEnvironment G) {
TypeRef typeRef = TypeUtils.getMemberTypeRef(member);
TypeRef typeRefSubst = ts.substTypeVariables(G, typeRef);
Expand Down Expand Up @@ -473,6 +492,12 @@ public boolean hasValidationProblem() {
return hasValidationProblem;
}

/** Returns all type variables */
public Collection<? extends TypeVariable> getTypeVariables() {
initMemberAggregate();
return memberTypeVars.values();
}

/**
* Returns a list of all return {@link TypeRef}s of the given {@link MemberType}s. If no {@link MemberType} is
* given, all {@link TypeRef}s are returned.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public TMethod create(String name) {
TFormalParameter tFPar = currFparDesc.create();
method.getFpars().add(tFPar);
}
method.getTypeVars().addAll(cma.getTypeVariables());
return method;
}

Expand Down

0 comments on commit ab30bd7

Please sign in to comment.