protected virtual void CheckReturnValue(ReturnStatement ret)
{
if (ret.Value == null) {
if (!currentRoutine.ReturnType.IsNull) {
report.Error(ret.Location,
"return value should be provided");
return;
}
}
else {
if (currentRoutine.ReturnType.IsNull) {
report.Error(ret.Location,
"return value should not be provided");
return;
}
ret.Value.Accept(this);
if (ret.Value is VoidExpression) {
ret.Value.NodeType = currentRoutine.ReturnType.NodeType;
}
else {
TypeData expectedType = currentRoutine.ReturnType.NodeType;
if (!ret.Value.NodeType.IsSubtypeOf(expectedType)) {
report.Error(ret.Location,
"the type of the destination: {0} is " +
"not a supertype of {1}",
expectedType.FullName,
ret.Value.NodeType.FullName);
return;
}
}
}
}