diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index c947ed0b775..f976028d4ae 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -649,7 +649,6 @@ public interface Errors { DiagnosticFactory0 TYPE_MISMATCH_IN_RANGE = DiagnosticFactory0.create(ERROR, WHEN_CONDITION_IN_RANGE); DiagnosticFactory1 EXPECTED_PARAMETER_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR); - DiagnosticFactory1 EXPECTED_RETURN_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR); DiagnosticFactory2> EXPECTED_PARAMETERS_NUMBER_MISMATCH = DiagnosticFactory2.create(ERROR, FUNCTION_PARAMETERS); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index 282096b79f0..34d01de87d6 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -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", diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetFunctionNotStubbed.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetFunctionNotStubbed.java index 0f49e44cb09..cba9a2c9494 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetFunctionNotStubbed.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetFunctionNotStubbed.java @@ -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 diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/FunctionsTypingVisitor.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/FunctionsTypingVisitor.kt index 36bafec883b..bbd73c2de17 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/FunctionsTypingVisitor.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/FunctionsTypingVisitor.kt @@ -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(