Skip to content

Commit

Permalink
[NTI] Remove code in FunctionType dealing with shadowing of type params.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=148470987
  • Loading branch information
dimvar authored and Tyler Breisacher committed Feb 27, 2017
1 parent 5ed98ed commit 6890d7c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
Expand Up @@ -286,8 +286,8 @@ public DeclaredFunctionType substituteNominalGenerics(NominalType nt) {
}
Map<String, JSType> 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));
}
Expand Down
26 changes: 7 additions & 19 deletions src/com/google/javascript/jscomp/newtypes/FunctionType.java
Expand Up @@ -965,36 +965,24 @@ private FunctionType substituteNominalGenerics(Map<String, JSType> typeMap) {
if (typeMap.isEmpty() || this.isTopFunction()) {
return this;
}
Map<String, JSType> 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<String, JSType> builder = ImmutableMap.builder();
for (Map.Entry<String, JSType> 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();
}
Expand Down

0 comments on commit 6890d7c

Please sign in to comment.