Drop diagnostic reported on lambda's return type

Because it's not allowed syntactically anymore.
Also adjust related methods within JetFunctionNotStubbed
This commit is contained in:
Denis Zharkov
2015-09-24 17:58:46 +03:00
parent c6377a0664
commit 60ebc689ad
4 changed files with 7 additions and 26 deletions
@@ -649,7 +649,6 @@ public interface Errors {
DiagnosticFactory0<JetWhenConditionInRange> TYPE_MISMATCH_IN_RANGE = DiagnosticFactory0.create(ERROR, WHEN_CONDITION_IN_RANGE);
DiagnosticFactory1<JetParameter, JetType> EXPECTED_PARAMETER_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR);
DiagnosticFactory1<JetTypeReference, JetType> EXPECTED_RETURN_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR);
DiagnosticFactory2<JetFunction, Integer, List<JetType>> EXPECTED_PARAMETERS_NUMBER_MISMATCH =
DiagnosticFactory2.create(ERROR, FUNCTION_PARAMETERS);
@@ -360,7 +360,6 @@ public class DefaultErrorMessages {
"Expected a value of type {0}. Assignment operation is not an expression, so it does not return any value", RENDER_TYPE);
MAP.put(EXPECTED_PARAMETER_TYPE_MISMATCH, "Expected parameter of type {0}", RENDER_TYPE);
MAP.put(EXPECTED_RETURN_TYPE_MISMATCH, "Expected return type {0}", RENDER_TYPE);
MAP.put(EXPECTED_PARAMETERS_NUMBER_MISMATCH, "Expected {0,choice,0#no parameters|1#one parameter of type|1<{0,number,integer} parameters of types} {1}", null, RENDER_COLLECTION_OF_TYPES);
MAP.put(IMPLICIT_CAST_TO_UNIT_OR_ANY, "Type is cast to ''{0}''. Please specify ''{0}'' as expected type, if you mean such cast",
@@ -55,41 +55,32 @@ public abstract class JetFunctionNotStubbed extends JetTypeParameterListOwnerNot
@Override
public boolean hasDeclaredReturnType() {
return getTypeReference() != null;
return false;
}
@Override
@Nullable
public JetTypeReference getReceiverTypeReference() {
PsiElement child = getFirstChild();
while (child != null) {
IElementType tt = child.getNode().getElementType();
if (tt == JetTokens.LPAR || tt == JetTokens.COLON) break;
if (child instanceof JetTypeReference) {
return (JetTypeReference) child;
}
child = child.getNextSibling();
}
return null;
}
@Override
@Nullable
public JetTypeReference getTypeReference() {
return TypeRefHelpersPackage.getTypeReference(this);
return null;
}
@Nullable
@Override
public JetTypeReference setTypeReference(@Nullable JetTypeReference typeRef) {
return TypeRefHelpersPackage.setTypeReference(this, getValueParameterList(), typeRef);
if (typeRef == null) return null;
throw new IllegalStateException("Function literals can't have type reference");
}
@Nullable
@Override
public PsiElement getColon() {
return findChildByType(JetTokens.COLON);
return null;
}
@Override
@@ -196,16 +196,8 @@ public class FunctionsTypingVisitor(facade: ExpressionTypingInternals) : Express
expectedReturnType: JetType?
): JetType? {
val functionLiteral = expression.getFunctionLiteral()
val declaredReturnType = functionLiteral.getTypeReference()?.let {
val type = components.typeResolver.resolveType(context.scope, it, context.trace, true)
if (expectedReturnType != null && !TypeUtils.noExpectedType(expectedReturnType)
&& !JetTypeChecker.DEFAULT.isSubtypeOf(type, expectedReturnType)) {
context.trace.report(EXPECTED_RETURN_TYPE_MISMATCH.on(it, expectedReturnType))
}
type
}
val expectedType = declaredReturnType ?: (expectedReturnType ?: NO_EXPECTED_TYPE)
val expectedType = expectedReturnType ?: NO_EXPECTED_TYPE
val functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(context.scope, functionDescriptor, context.trace)
val newContext = context.replaceScope(functionInnerScope).replaceExpectedType(expectedType)
@@ -214,7 +206,7 @@ public class FunctionsTypingVisitor(facade: ExpressionTypingInternals) : Express
val typeOfBodyExpression = // Type-check the body
components.expressionTypingServices.getBlockReturnedType(functionLiteral.getBodyExpression()!!, COERCION_TO_UNIT, newContext).type
return declaredReturnType ?: computeReturnTypeBasedOnReturnExpressions(functionLiteral, context, typeOfBodyExpression)
return computeReturnTypeBasedOnReturnExpressions(functionLiteral, context, typeOfBodyExpression)
}
private fun computeReturnTypeBasedOnReturnExpressions(