Unused code removed

This commit is contained in:
Andrey Breslav
2013-08-19 13:02:37 +04:00
parent 185b5013fe
commit 0e1ba96e2c
2 changed files with 20 additions and 62 deletions
@@ -320,8 +320,7 @@ public class DescriptorResolver {
DeferredType.create(trace, new RecursionIntolerantLazyValueWithDefault<JetType>(ErrorUtils.createErrorType("Recursive dependency")) { DeferredType.create(trace, new RecursionIntolerantLazyValueWithDefault<JetType>(ErrorUtils.createErrorType("Recursive dependency")) {
@Override @Override
protected JetType compute() { protected JetType compute() {
//JetFlowInformationProvider flowInformationProvider = computeFlowData(function, bodyExpression); JetType type = expressionTypingServices.getBodyExpressionType(trace, scope, function, functionDescriptor);
JetType type = expressionTypingServices.inferFunctionReturnType(scope, function, functionDescriptor, trace);
return transformAnonymousTypeIfNeeded(functionDescriptor, function, type, trace); return transformAnonymousTypeIfNeeded(functionDescriptor, function, type, trace);
} }
}); });
@@ -17,16 +17,14 @@
package org.jetbrains.jet.lang.types.expressions; package org.jetbrains.jet.lang.types.expressions;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.collect.Lists;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; 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.ScriptDescriptor;
import org.jetbrains.jet.lang.descriptors.impl.FunctionDescriptorUtil;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.*; import org.jetbrains.jet.lang.resolve.*;
import org.jetbrains.jet.lang.resolve.calls.CallExpressionResolver; 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.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.WritableScope; import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl; 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.ErrorUtils;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.JetTypeInfo; 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 org.jetbrains.jet.lexer.JetTokens;
import javax.inject.Inject; 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.resolve.BindingContext.STATEMENT;
import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE; import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
import static org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils.makeTraceInterceptingTypeMismatch; import static org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils.makeTraceInterceptingTypeMismatch;
@@ -146,16 +143,6 @@ public class ExpressionTypingServices {
return expressionTypingFacade.getTypeInfo(expression, context); return expressionTypingFacade.getTypeInfo(expression, context);
} }
@NotNull
public JetType inferFunctionReturnType(@NotNull JetScope outerScope, @NotNull JetDeclarationWithBody function, @NotNull FunctionDescriptor functionDescriptor, @NotNull BindingTrace trace) {
Map<JetExpression, JetType> typeMap = collectReturnedExpressionsWithTypes(trace, outerScope, function, functionDescriptor);
Collection<JetType> 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) { 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; return r;
} }
private Map<JetExpression, JetType> collectReturnedExpressionsWithTypes( @NotNull
final @NotNull BindingTrace trace, public JetType getBodyExpressionType(
JetScope outerScope, @NotNull BindingTrace trace,
final JetDeclarationWithBody function, @NotNull JetScope outerScope,
FunctionDescriptor functionDescriptor) { @NotNull JetDeclarationWithBody function,
@NotNull FunctionDescriptor functionDescriptor
) {
JetExpression bodyExpression = function.getBodyExpression(); JetExpression bodyExpression = function.getBodyExpression();
assert bodyExpression != null; assert bodyExpression != null;
JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(outerScope, functionDescriptor, trace); 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<JetExpression> 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<JetDeclarationWithBody>() {
@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 ExpressionTypingContext context = ExpressionTypingContext.newContext(
public Void visitFunctionLiteralExpression(JetFunctionLiteralExpression expression, JetDeclarationWithBody outerFunction) { this, trace, functionInnerScope, DataFlowInfo.EMPTY, NO_EXPECTED_TYPE, ExpressionPosition.FREE
return super.visitFunctionLiteralExpression(expression, expression.getFunctionLiteral()); );
} JetTypeInfo typeInfo = expressionTypingFacade.getTypeInfo(bodyExpression, context, !function.hasBlockBody());
@Override trace.record(STATEMENT, bodyExpression, false);
public Void visitNamedFunction(JetNamedFunction function, JetDeclarationWithBody outerFunction) { JetType type = typeInfo.getType();
return super.visitNamedFunction(function, function); if (type != null) {
} return type;
}, function);
} }
else { else {
returnedExpressions.add(bodyExpression); return ErrorUtils.createErrorType("Error function type");
} }
Map<JetExpression, JetType> typeMap = new HashMap<JetExpression, JetType>();
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*/ /*package*/