Skip to content

Commit

Permalink
Convert the type-transformation handling to use TypeI.
Browse files Browse the repository at this point in the history
The tests are still only run with the old type checker.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=153829588
  • Loading branch information
dimvar committed Apr 21, 2017
1 parent 509e3ad commit 1f46cb7
Show file tree
Hide file tree
Showing 19 changed files with 402 additions and 266 deletions.
2 changes: 1 addition & 1 deletion src/com/google/javascript/jscomp/ConformanceRules.java
Expand Up @@ -511,7 +511,7 @@ private ConformanceResult checkConformance(NodeTraversal t, Node n, Property pro
if (ownerFun.isConstructor()) { if (ownerFun.isConstructor()) {
foundType = ownerFun.getInstanceType(); foundType = ownerFun.getInstanceType();
} }
} else if (foundObj.isGeneric()) { } else if (foundObj.isGenericObjectType()) {
foundType = foundObj.getRawType(); foundType = foundObj.getRawType();
} }
} }
Expand Down
Expand Up @@ -973,7 +973,7 @@ private ObjectTypeI getTypeWithProperty(String field, TypeI type) {
} }


// Unwrap templatized types, they are not unique at runtime. // Unwrap templatized types, they are not unique at runtime.
if (foundType != null && foundType.isGeneric()) { if (foundType != null && foundType.isGenericObjectType()) {
foundType = foundType.getRawType(); foundType = foundType.getRawType();
} }


Expand Down
23 changes: 23 additions & 0 deletions src/com/google/javascript/jscomp/GlobalTypeInfo.java
Expand Up @@ -48,8 +48,10 @@
import com.google.javascript.rhino.JSDocInfo; import com.google.javascript.rhino.JSDocInfo;
import com.google.javascript.rhino.JSTypeExpression; import com.google.javascript.rhino.JSTypeExpression;
import com.google.javascript.rhino.Node; import com.google.javascript.rhino.Node;
import com.google.javascript.rhino.ObjectTypeI;
import com.google.javascript.rhino.Token; import com.google.javascript.rhino.Token;
import com.google.javascript.rhino.TypeI; import com.google.javascript.rhino.TypeI;
import com.google.javascript.rhino.TypeIEnv;
import com.google.javascript.rhino.TypeIRegistry; import com.google.javascript.rhino.TypeIRegistry;
import com.google.javascript.rhino.jstype.JSTypeNative; import com.google.javascript.rhino.jstype.JSTypeNative;
import java.util.ArrayList; import java.util.ArrayList;
Expand Down Expand Up @@ -2883,8 +2885,29 @@ public TypeI createUnionType(List<? extends TypeI> members) {
return result; return result;
} }


@Override
public TypeI evaluateTypeExpression(JSTypeExpression expr, TypeIEnv<TypeI> typeEnv) {
throw new UnsupportedOperationException();
}

@Override @Override
public TypeI evaluateTypeExpressionInGlobalScope(JSTypeExpression expr) { public TypeI evaluateTypeExpressionInGlobalScope(JSTypeExpression expr) {
return createTypeFromCommentNode(expr.getRoot()); return createTypeFromCommentNode(expr.getRoot());
} }

@Override
public TypeI createRecordType(Map<String, ? extends TypeI> props) {
throw new UnsupportedOperationException();
}

@Override
public TypeI instantiateGenericType(
ObjectTypeI genericType, ImmutableList<? extends TypeI> typeArgs) {
throw new UnsupportedOperationException();
}

@Override
public TypeI buildRecordTypeFromObject(ObjectTypeI obj) {
throw new UnsupportedOperationException();
}
} }
6 changes: 4 additions & 2 deletions src/com/google/javascript/jscomp/TypeInference.java
Expand Up @@ -1386,8 +1386,10 @@ private Map<TemplateType, JSType> evaluateTypeTransformations(
} }
// Evaluate the type transformation expression using the current // Evaluate the type transformation expression using the current
// known types for the template type variables // known types for the template type variables
JSType transformedType = ttlObj.eval(type.getTypeTransformation(), @SuppressWarnings({"unchecked", "rawtypes"})
ImmutableMap.<String, JSType>copyOf(typeVars)); JSType transformedType = (JSType) ttlObj.eval(
type.getTypeTransformation(),
(ImmutableMap) ImmutableMap.copyOf(typeVars));
result.put(type, transformedType); result.put(type, transformedType);
// Add the transformed type to the type variables // Add the transformed type to the type variables
typeVars.put(type.getReferenceName(), transformedType); typeVars.put(type.getReferenceName(), transformedType);
Expand Down
2 changes: 1 addition & 1 deletion src/com/google/javascript/jscomp/TypeMismatch.java
Expand Up @@ -126,7 +126,7 @@ static void recordImplicitInterfaceUses(
private static TypeI removeNullUndefinedAndTemplates(TypeI t) { private static TypeI removeNullUndefinedAndTemplates(TypeI t) {
TypeI result = t.restrictByNotNullOrUndefined(); TypeI result = t.restrictByNotNullOrUndefined();
ObjectTypeI obj = result.toMaybeObjectType(); ObjectTypeI obj = result.toMaybeObjectType();
if (obj != null && obj.isGeneric()) { if (obj != null && obj.isGenericObjectType()) {
return obj.instantiateGenericsWithUnknown(); return obj.instantiateGenericsWithUnknown();
} }
return result; return result;
Expand Down

0 comments on commit 1f46cb7

Please sign in to comment.