No need to produce error types when RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED is reported

This commit is contained in:
Andrey Breslav
2013-08-21 20:06:06 +04:00
parent 3f3ee378f3
commit a51ea10f55
8 changed files with 27 additions and 21 deletions
@@ -522,18 +522,16 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
SimpleFunctionDescriptor functionDescriptor = context.trace.get(FUNCTION, labelTargetElement);
if (functionDescriptor != null) {
expectedType = DescriptorUtils.getFunctionExpectedReturnType(functionDescriptor, labelTargetElement);
boolean inLambdaWithNoExplicitType = expectedType == TypeUtils.NO_EXPECTED_TYPE;
if (inLambdaWithNoExplicitType) {
// expectedType is NO_EXPECTED_TYPE iff the return type of the corresponding function descriptor is not computed yet
// our temporary policy is to prohibit returns in this case. It mostly applies to local returns in lambdas
context.trace.report(RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED.on(expression));
resultType = ErrorUtils.createErrorType(RETURN_NOT_ALLOWED_MESSAGE);
}
else if (functionDescriptor != containingFunctionDescriptor) {
if (functionDescriptor != containingFunctionDescriptor) {
// Qualified, non-local
context.trace.report(RETURN_NOT_ALLOWED.on(expression));
resultType = ErrorUtils.createErrorType(RETURN_NOT_ALLOWED_MESSAGE);
}
else if (expectedType == TypeUtils.NO_EXPECTED_TYPE) {
// expectedType is NO_EXPECTED_TYPE iff the return type of the corresponding function descriptor is not computed yet
// our temporary policy is to prohibit returns in this case. It mostly applies to local returns in lambdas
context.trace.report(RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED.on(expression));
}
}
else {
context.trace.report(NOT_A_RETURN_LABEL.on(expression, expression.getLabelName()));