addError(node,
Fmt.S("Class name is missing in cast operation."));
return actualType;
}
TypeInfo castToType = _env.getTypeRetriever().getTypeInfo(castTo);
if (castToType == null) {
addError(node,
Fmt.S("Cannot resolve string '%s' to a type.", castTo));
return actualType;
}
else if (actualType == null) {
// If the acutal type is null, then there must be an error
// added to already. Just return the castTo type to continue
// on the type checking.
return castToType;
}
else if (actualType.isCompatible(castToType)) {
// isCompatible() returns true if actualType can be widened or
// narrowed to the castToType.
return castToType;
}
else {
addError(node,
Fmt.S("Cannot cast '%s' to '%s' since they are not compatible.",
actualType.getName(), castToType.getName()));
// An error is already logged. Return the castTo type so we can
// continue on the type checking.
return castToType;
}
}