Blocks denoted in the BindingContext
This commit is contained in:
@@ -25,4 +25,6 @@ public interface BindingContext {
|
||||
JetType resolveTypeReference(JetTypeReference typeReference);
|
||||
PsiElement resolveToDeclarationPsiElement(JetReferenceExpression referenceExpression);
|
||||
PsiElement getDeclarationPsiElement(DeclarationDescriptor descriptor);
|
||||
|
||||
boolean isBlock(JetFunctionLiteralExpression expression);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,9 @@ import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
@@ -18,6 +20,7 @@ public class BindingTraceContext extends BindingTrace implements BindingContext
|
||||
private final Map<JetTypeReference, JetType> types = new HashMap<JetTypeReference, JetType>();
|
||||
private final Map<DeclarationDescriptor, PsiElement> descriptorToDeclarations = new HashMap<DeclarationDescriptor, PsiElement>();
|
||||
private final Map<PsiElement, DeclarationDescriptor> declarationsToDescriptors = new HashMap<PsiElement, DeclarationDescriptor>();
|
||||
private final Set<JetFunctionLiteralExpression> blocks = new HashSet<JetFunctionLiteralExpression>();
|
||||
private JetScope toplevelScope;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -53,6 +56,11 @@ public class BindingTraceContext extends BindingTrace implements BindingContext
|
||||
declarationsToDescriptors.put(declaration, descriptor.getOriginal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordBlock(JetFunctionLiteralExpression expression) {
|
||||
blocks.add(expression);
|
||||
}
|
||||
|
||||
public void setToplevelScope(JetScope toplevelScope) {
|
||||
this.toplevelScope = toplevelScope;
|
||||
}
|
||||
@@ -122,4 +130,9 @@ public class BindingTraceContext extends BindingTrace implements BindingContext
|
||||
public PsiElement getDeclarationPsiElement(DeclarationDescriptor descriptor) {
|
||||
return descriptorToDeclarations.get(descriptor.getOriginal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlock(JetFunctionLiteralExpression expression) {
|
||||
return expression.hasParameterSpecification() || blocks.contains(expression);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,10 @@ public class BindingTrace {
|
||||
|
||||
}
|
||||
|
||||
public void recordBlock(JetFunctionLiteralExpression expression) {
|
||||
|
||||
}
|
||||
|
||||
public void removeReferenceResolution(@NotNull JetReferenceExpression referenceExpression) {
|
||||
|
||||
}
|
||||
|
||||
@@ -378,6 +378,7 @@ public class JetTypeInferrer {
|
||||
@Override
|
||||
public void visitFunctionLiteralExpression(JetFunctionLiteralExpression expression) {
|
||||
if (preferBlock && !expression.hasParameterSpecification()) {
|
||||
trace.recordBlock(expression);
|
||||
result = getBlockReturnedType(scope, expression.getBody(), LabeledJumpDomain.ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user