Record 'a!!', 'a ?: b' special calls by operation reference

This commit is contained in:
Svetlana Isakova
2014-05-02 13:18:40 +04:00
parent cf81a44e02
commit ae9d2d015e
4 changed files with 10 additions and 7 deletions
@@ -32,7 +32,10 @@ import org.jetbrains.jet.lang.psi.JetSimpleNameExpression
/**
* For expressions like <code>a(), a[i], a.b.c(), +a, a + b, (a()), a(): Int, @label a()</code>
* returns a corresponding call
* returns a corresponding call.
*
* Note: special construction like <code>a!!, a ?: b, if (c) a else b</code> are resolved as calls,
* so there is a corresponding call for them.
*/
fun JetExpression.getCorrespondingCall(bindingContext: BindingContext): Call? {
val expr = JetPsiUtil.deparenthesize(this)
@@ -713,7 +713,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
JetSimpleNameExpression operationSign = expression.getOperationReference();
assert operationSign.getReferencedNameElementType() == JetTokens.EXCLEXCL;
Call call = createCallForSpecialConstruction(expression, Collections.singletonList(baseExpression));
Call call = createCallForSpecialConstruction(expression, expression.getOperationReference(), Collections.singletonList(baseExpression));
components.controlStructureTypingUtils.resolveSpecialConstructionAsCall(
call, "ExclExcl", Collections.singletonList("baseExpr"), Collections.singletonList(true), context, null);
JetTypeInfo baseTypeInfo = BindingContextUtils.getRecordedTypeInfo(baseExpression, context.trace.getBindingContext());
@@ -982,7 +982,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
return JetTypeInfo.create(null, context.dataFlowInfo);
}
Call call = createCallForSpecialConstruction(expression, Lists.newArrayList(left, right));
Call call = createCallForSpecialConstruction(expression, expression.getOperationReference(), Lists.newArrayList(left, right));
ResolvedCall<FunctionDescriptor> resolvedCall = components.controlStructureTypingUtils.resolveSpecialConstructionAsCall(
call, "Elvis", Lists.newArrayList("left", "right"), Lists.newArrayList(true, false), contextWithExpectedType, null);
JetTypeInfo leftTypeInfo = BindingContextUtils.getRecordedTypeInfo(left, context.trace.getBindingContext());
@@ -158,6 +158,7 @@ public class ControlStructureTypingUtils {
/*package*/ static Call createCallForSpecialConstruction(
@NotNull final JetExpression expression,
@NotNull final JetExpression calleeExpression,
@NotNull List<? extends JetExpression> arguments
) {
final List<ValueArgument> valueArguments = Lists.newArrayList();
@@ -186,7 +187,7 @@ public class ControlStructureTypingUtils {
@Nullable
@Override
public JetExpression getCalleeExpression() {
return expression;
return calleeExpression;
}
@Nullable
@@ -345,8 +346,7 @@ public class ControlStructureTypingUtils {
if (status.hasErrorInConstrainingTypes()) {
return;
}
JetExpression expression = call.getCalleeExpression();
if (expression == null) return;
JetExpression expression = (JetExpression) call.getCallElement();
if (status.hasOnlyErrorsFromPosition(ConstraintPosition.EXPECTED_TYPE_POSITION) || status.hasConflictingConstraints()) {
expression.accept(checkTypeVisitor, new CheckTypeContext(trace, data.expectedType));
return;
@@ -115,7 +115,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
}
JetBlockExpression thenBlock = JetPsiFactory.wrapInABlock(thenBranch);
JetBlockExpression elseBlock = JetPsiFactory.wrapInABlock(elseBranch);
Call callForIf = createCallForSpecialConstruction(ifExpression, Lists.newArrayList(thenBlock, elseBlock));
Call callForIf = createCallForSpecialConstruction(ifExpression, ifExpression, Lists.newArrayList(thenBlock, elseBlock));
MutableDataFlowInfoForArguments dataFlowInfoForArguments =
createDataFlowInfoForArgumentsForIfCall(callForIf, thenInfo, elseInfo);
ResolvedCall<FunctionDescriptor> resolvedCall = components.controlStructureTypingUtils.resolveSpecialConstructionAsCall(