From ab30bd7c21a3684202756f75f865e6f227c66ca1 Mon Sep 17 00:00:00 2001 From: mmews Date: Tue, 16 Apr 2024 15:13:08 +0200 Subject: [PATCH] fix handling type vars of composed methods --- .../scoping/members/ComposedMemberInfo.java | 27 ++++++++++++++++++- .../n4js/scoping/members/MethodFactory.java | 1 + 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/plugins/org.eclipse.n4js/src/org/eclipse/n4js/scoping/members/ComposedMemberInfo.java b/plugins/org.eclipse.n4js/src/org/eclipse/n4js/scoping/members/ComposedMemberInfo.java index 4658213ca0..0d38a7c5e4 100644 --- a/plugins/org.eclipse.n4js/src/org/eclipse/n4js/scoping/members/ComposedMemberInfo.java +++ b/plugins/org.eclipse.n4js/src/org/eclipse/n4js/scoping/members/ComposedMemberInfo.java @@ -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; @@ -24,8 +26,10 @@ 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; @@ -33,6 +37,7 @@ 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; @@ -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 memberTypeVars = new LinkedHashMap<>(); private final Multimap typeRefsMap = LinkedHashMultimap.create(); private final List typeRefs = new ArrayList<>(); private final List methodTypeRefsVoid = new ArrayList<>(); private final List methodTypeRefsNonVoid = new ArrayList<>(); private final Map typeRef2G = new HashMap<>(); - private final List fParameters = new ArrayList<>(); + private boolean isVariadicButLastFParIsDifferent = false; /** @@ -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); @@ -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); @@ -473,6 +492,12 @@ public boolean hasValidationProblem() { return hasValidationProblem; } + /** Returns all type variables */ + public Collection 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. diff --git a/plugins/org.eclipse.n4js/src/org/eclipse/n4js/scoping/members/MethodFactory.java b/plugins/org.eclipse.n4js/src/org/eclipse/n4js/scoping/members/MethodFactory.java index 09bdf7b60d..97fdb298e0 100644 --- a/plugins/org.eclipse.n4js/src/org/eclipse/n4js/scoping/members/MethodFactory.java +++ b/plugins/org.eclipse.n4js/src/org/eclipse/n4js/scoping/members/MethodFactory.java @@ -88,6 +88,7 @@ public TMethod create(String name) { TFormalParameter tFPar = currFparDesc.create(); method.getFpars().add(tFPar); } + method.getTypeVars().addAll(cma.getTypeVariables()); return method; }