use of com.google.javascript.jscomp.newtypes.JSType in project closure-compiler by google.
the class NewTypeInference method analyzeAssertionCall.
private EnvTypePair analyzeAssertionCall(Node callNode, TypeEnv env, AssertionFunctionSpec assertionFunctionSpec) {
analyzeExprFwdIgnoreResult(callNode.getFirstChild(), env);
Node firstParam = callNode.getSecondChild();
if (firstParam == null) {
return new EnvTypePair(env, UNKNOWN);
}
for (Node assertionArgument : firstParam.siblings()) {
analyzeExprFwdIgnoreResult(assertionArgument, env);
}
Node assertedNode = assertionFunctionSpec.getAssertedParam(firstParam);
if (assertedNode == null) {
return new EnvTypePair(env, UNKNOWN);
}
JSType assertedType = assertionFunctionSpec.getAssertedNewType(callNode, currentScope);
if (assertedType.isUnknown()) {
warnings.add(JSError.make(callNode, UNKNOWN_ASSERTION_TYPE));
}
EnvTypePair pair = analyzeExprFwd(assertedNode, env, UNKNOWN, assertedType);
boolean haveCommonSubtype = JSType.haveCommonSubtype(assertedType, pair.type);
if (!pair.type.isSubtypeOf(assertedType) && haveCommonSubtype) {
// We do this because the assertion needs to return a subtype of the
// asserted type to its context, but sometimes the asserted expression
// can't be specialized.
pair.type = assertedType;
}
if (!haveCommonSubtype) {
JSType t = analyzeExprFwd(assertedNode, env).type.substituteGenericsWithUnknown();
if (t.isSubtypeOf(assertedType)) {
pair.type = t;
} else {
if (!firstParam.isFalse()) {
// Don't warn for an explicit: assert(false);
warnings.add(JSError.make(assertedNode, ASSERT_FALSE));
}
pair.type = UNKNOWN;
pair.env = env;
}
}
return pair;
}
Aggregations