From 6890d7c0ee424fb8e68a764393e85c21eed62374 Mon Sep 17 00:00:00 2001 From: dimvar Date: Fri, 24 Feb 2017 09:55:42 -0800 Subject: [PATCH] [NTI] Remove code in FunctionType dealing with shadowing of type params. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=148470987 --- .../jscomp/newtypes/DeclaredFunctionType.java | 4 +-- .../jscomp/newtypes/FunctionType.java | 26 +++++-------------- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/src/com/google/javascript/jscomp/newtypes/DeclaredFunctionType.java b/src/com/google/javascript/jscomp/newtypes/DeclaredFunctionType.java index be434791139..4a5a8004f01 100644 --- a/src/com/google/javascript/jscomp/newtypes/DeclaredFunctionType.java +++ b/src/com/google/javascript/jscomp/newtypes/DeclaredFunctionType.java @@ -286,8 +286,8 @@ public DeclaredFunctionType substituteNominalGenerics(NominalType nt) { } Map typeMap = nt.getTypeMap(); Preconditions.checkState(!typeMap.isEmpty()); - // Before switching to unique generated names for type variables, a method's type variables - // could shadow type variables defined on the class. Check that it no longer happens. + // Before we switched to unique generated names for type variables, a method's type variables + // could shadow type variables defined on the class. Check that this no longer happens. for (String typeParam : typeParameters) { Preconditions.checkState(!typeMap.containsKey(typeParam)); } diff --git a/src/com/google/javascript/jscomp/newtypes/FunctionType.java b/src/com/google/javascript/jscomp/newtypes/FunctionType.java index 4eff0531ab6..b4c54836bb0 100644 --- a/src/com/google/javascript/jscomp/newtypes/FunctionType.java +++ b/src/com/google/javascript/jscomp/newtypes/FunctionType.java @@ -965,36 +965,24 @@ private FunctionType substituteNominalGenerics(Map typeMap) { if (typeMap.isEmpty() || this.isTopFunction()) { return this; } - Map reducedMap = typeMap; if (!this.commonTypes.MAP_TO_UNKNOWN.equals(typeMap)) { - boolean foundShadowedTypeParam = false; + // Before we switched to unique generated names for type variables, a method's type variables + // could shadow type variables defined on the class. Check that this no longer happens. for (String typeParam : this.typeParameters) { - if (typeMap.containsKey(typeParam)) { - foundShadowedTypeParam = true; - break; - } - } - if (foundShadowedTypeParam) { - ImmutableMap.Builder builder = ImmutableMap.builder(); - for (Map.Entry entry : typeMap.entrySet()) { - if (!typeParameters.contains(entry.getKey())) { - builder.put(entry); - } - } - reducedMap = builder.build(); + Preconditions.checkState(!typeMap.containsKey(typeParam)); } } FunctionTypeBuilder builder = new FunctionTypeBuilder(this.commonTypes); for (JSType reqFormal : this.requiredFormals) { - builder.addReqFormal(reqFormal.substituteGenerics(reducedMap)); + builder.addReqFormal(reqFormal.substituteGenerics(typeMap)); } for (JSType optFormal : this.optionalFormals) { - builder.addOptFormal(optFormal.substituteGenerics(reducedMap)); + builder.addOptFormal(optFormal.substituteGenerics(typeMap)); } if (this.restFormals != null) { - builder.addRestFormals(restFormals.substituteGenerics(reducedMap)); + builder.addRestFormals(restFormals.substituteGenerics(typeMap)); } - builder.addRetType(this.returnType.substituteGenerics(reducedMap)); + builder.addRetType(this.returnType.substituteGenerics(typeMap)); if (isLoose()) { builder.addLoose(); }