From 0e1ba96e2cb028a48bd8c41b45b86b85f3e6ec7c Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Mon, 19 Aug 2013 13:02:37 +0400 Subject: [PATCH] Unused code removed --- .../jet/lang/resolve/DescriptorResolver.java | 3 +- .../expressions/ExpressionTypingServices.java | 79 +++++-------------- 2 files changed, 20 insertions(+), 62 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java index ac6399a0a82..892a276812c 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java @@ -320,8 +320,7 @@ public class DescriptorResolver { DeferredType.create(trace, new RecursionIntolerantLazyValueWithDefault(ErrorUtils.createErrorType("Recursive dependency")) { @Override protected JetType compute() { - //JetFlowInformationProvider flowInformationProvider = computeFlowData(function, bodyExpression); - JetType type = expressionTypingServices.inferFunctionReturnType(scope, function, functionDescriptor, trace); + JetType type = expressionTypingServices.getBodyExpressionType(trace, scope, function, functionDescriptor); return transformAnonymousTypeIfNeeded(functionDescriptor, function, type, trace); } }); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingServices.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingServices.java index 803579e026a..2cf806a31af 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingServices.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingServices.java @@ -17,16 +17,14 @@ package org.jetbrains.jet.lang.types.expressions; import com.google.common.base.Function; -import com.google.common.collect.Lists; import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiElement; import com.intellij.psi.tree.IElementType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; -import org.jetbrains.jet.lang.descriptors.impl.FunctionDescriptorUtil; import org.jetbrains.jet.lang.descriptors.ScriptDescriptor; +import org.jetbrains.jet.lang.descriptors.impl.FunctionDescriptorUtil; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.*; import org.jetbrains.jet.lang.resolve.calls.CallExpressionResolver; @@ -36,7 +34,6 @@ import org.jetbrains.jet.lang.resolve.calls.context.ExpressionPosition; import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.WritableScope; import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl; -import org.jetbrains.jet.lang.types.CommonSupertypes; import org.jetbrains.jet.lang.types.ErrorUtils; import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetTypeInfo; @@ -44,9 +41,9 @@ import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; import org.jetbrains.jet.lexer.JetTokens; import javax.inject.Inject; -import java.util.*; +import java.util.Iterator; +import java.util.List; -import static org.jetbrains.jet.lang.resolve.BindingContext.LABEL_TARGET; import static org.jetbrains.jet.lang.resolve.BindingContext.STATEMENT; import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE; import static org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils.makeTraceInterceptingTypeMismatch; @@ -146,16 +143,6 @@ public class ExpressionTypingServices { return expressionTypingFacade.getTypeInfo(expression, context); } - @NotNull - public JetType inferFunctionReturnType(@NotNull JetScope outerScope, @NotNull JetDeclarationWithBody function, @NotNull FunctionDescriptor functionDescriptor, @NotNull BindingTrace trace) { - Map typeMap = collectReturnedExpressionsWithTypes(trace, outerScope, function, functionDescriptor); - Collection types = typeMap.values(); - return types.isEmpty() - ? KotlinBuiltIns.getInstance().getNothingType() - : CommonSupertypes.commonSupertype(types); - } - - ///////////////////////////////////////////////////////// public void checkFunctionReturnType(@NotNull JetScope functionInnerScope, @NotNull JetDeclarationWithBody function, @NotNull FunctionDescriptor functionDescriptor, @NotNull DataFlowInfo dataFlowInfo, @Nullable JetType expectedReturnType, BindingTrace trace) { @@ -223,58 +210,30 @@ public class ExpressionTypingServices { return r; } - private Map collectReturnedExpressionsWithTypes( - final @NotNull BindingTrace trace, - JetScope outerScope, - final JetDeclarationWithBody function, - FunctionDescriptor functionDescriptor) { + @NotNull + public JetType getBodyExpressionType( + @NotNull BindingTrace trace, + @NotNull JetScope outerScope, + @NotNull JetDeclarationWithBody function, + @NotNull FunctionDescriptor functionDescriptor + ) { JetExpression bodyExpression = function.getBodyExpression(); assert bodyExpression != null; JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(outerScope, functionDescriptor, trace); - expressionTypingFacade.getTypeInfo(bodyExpression, ExpressionTypingContext.newContext( - this, - trace, functionInnerScope, DataFlowInfo.EMPTY, NO_EXPECTED_TYPE, ExpressionPosition.FREE), !function.hasBlockBody()); - //todo function literals - final Collection returnedExpressions = Lists.newArrayList(); - if (function.hasBlockBody()) { - //now this code is never invoked!, it should be invoked for inference of return type of function literal with local returns - bodyExpression.accept(new JetTreeVisitor() { - @Override - public Void visitReturnExpression(JetReturnExpression expression, JetDeclarationWithBody outerFunction) { - JetSimpleNameExpression targetLabel = expression.getTargetLabel(); - PsiElement element = targetLabel != null ? trace.get(LABEL_TARGET, targetLabel) : null; - if (element == function || (targetLabel == null && outerFunction == function)) { - returnedExpressions.add(expression); - } - return null; - } - @Override - public Void visitFunctionLiteralExpression(JetFunctionLiteralExpression expression, JetDeclarationWithBody outerFunction) { - return super.visitFunctionLiteralExpression(expression, expression.getFunctionLiteral()); - } + ExpressionTypingContext context = ExpressionTypingContext.newContext( + this, trace, functionInnerScope, DataFlowInfo.EMPTY, NO_EXPECTED_TYPE, ExpressionPosition.FREE + ); + JetTypeInfo typeInfo = expressionTypingFacade.getTypeInfo(bodyExpression, context, !function.hasBlockBody()); - @Override - public Void visitNamedFunction(JetNamedFunction function, JetDeclarationWithBody outerFunction) { - return super.visitNamedFunction(function, function); - } - }, function); + trace.record(STATEMENT, bodyExpression, false); + JetType type = typeInfo.getType(); + if (type != null) { + return type; } else { - returnedExpressions.add(bodyExpression); + return ErrorUtils.createErrorType("Error function type"); } - Map typeMap = new HashMap(); - for (JetExpression returnedExpression : returnedExpressions) { - JetType cachedType = trace.getBindingContext().get(BindingContext.EXPRESSION_TYPE, returnedExpression); - trace.record(STATEMENT, returnedExpression, false); - if (cachedType != null) { - typeMap.put(returnedExpression, cachedType); - } - else { - typeMap.put(returnedExpression, ErrorUtils.createErrorType("Error function type")); - } - } - return typeMap; } /*package*/