Unused code removed
This commit is contained in:
@@ -320,8 +320,7 @@ public class DescriptorResolver {
|
||||
DeferredType.create(trace, new RecursionIntolerantLazyValueWithDefault<JetType>(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);
|
||||
}
|
||||
});
|
||||
|
||||
+19
-60
@@ -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<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) {
|
||||
@@ -223,58 +210,30 @@ public class ExpressionTypingServices {
|
||||
return r;
|
||||
}
|
||||
|
||||
private Map<JetExpression, JetType> 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<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
|
||||
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<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*/
|
||||
|
||||
Reference in New Issue
Block a user