Record 'a!!', 'a ?: b' special calls by operation reference
This commit is contained in:
@@ -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>
|
* 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? {
|
fun JetExpression.getCorrespondingCall(bindingContext: BindingContext): Call? {
|
||||||
val expr = JetPsiUtil.deparenthesize(this)
|
val expr = JetPsiUtil.deparenthesize(this)
|
||||||
|
|||||||
+2
-2
@@ -713,7 +713,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
JetSimpleNameExpression operationSign = expression.getOperationReference();
|
JetSimpleNameExpression operationSign = expression.getOperationReference();
|
||||||
assert operationSign.getReferencedNameElementType() == JetTokens.EXCLEXCL;
|
assert operationSign.getReferencedNameElementType() == JetTokens.EXCLEXCL;
|
||||||
|
|
||||||
Call call = createCallForSpecialConstruction(expression, Collections.singletonList(baseExpression));
|
Call call = createCallForSpecialConstruction(expression, expression.getOperationReference(), Collections.singletonList(baseExpression));
|
||||||
components.controlStructureTypingUtils.resolveSpecialConstructionAsCall(
|
components.controlStructureTypingUtils.resolveSpecialConstructionAsCall(
|
||||||
call, "ExclExcl", Collections.singletonList("baseExpr"), Collections.singletonList(true), context, null);
|
call, "ExclExcl", Collections.singletonList("baseExpr"), Collections.singletonList(true), context, null);
|
||||||
JetTypeInfo baseTypeInfo = BindingContextUtils.getRecordedTypeInfo(baseExpression, context.trace.getBindingContext());
|
JetTypeInfo baseTypeInfo = BindingContextUtils.getRecordedTypeInfo(baseExpression, context.trace.getBindingContext());
|
||||||
@@ -982,7 +982,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
return JetTypeInfo.create(null, context.dataFlowInfo);
|
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(
|
ResolvedCall<FunctionDescriptor> resolvedCall = components.controlStructureTypingUtils.resolveSpecialConstructionAsCall(
|
||||||
call, "Elvis", Lists.newArrayList("left", "right"), Lists.newArrayList(true, false), contextWithExpectedType, null);
|
call, "Elvis", Lists.newArrayList("left", "right"), Lists.newArrayList(true, false), contextWithExpectedType, null);
|
||||||
JetTypeInfo leftTypeInfo = BindingContextUtils.getRecordedTypeInfo(left, context.trace.getBindingContext());
|
JetTypeInfo leftTypeInfo = BindingContextUtils.getRecordedTypeInfo(left, context.trace.getBindingContext());
|
||||||
|
|||||||
+3
-3
@@ -158,6 +158,7 @@ public class ControlStructureTypingUtils {
|
|||||||
|
|
||||||
/*package*/ static Call createCallForSpecialConstruction(
|
/*package*/ static Call createCallForSpecialConstruction(
|
||||||
@NotNull final JetExpression expression,
|
@NotNull final JetExpression expression,
|
||||||
|
@NotNull final JetExpression calleeExpression,
|
||||||
@NotNull List<? extends JetExpression> arguments
|
@NotNull List<? extends JetExpression> arguments
|
||||||
) {
|
) {
|
||||||
final List<ValueArgument> valueArguments = Lists.newArrayList();
|
final List<ValueArgument> valueArguments = Lists.newArrayList();
|
||||||
@@ -186,7 +187,7 @@ public class ControlStructureTypingUtils {
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public JetExpression getCalleeExpression() {
|
public JetExpression getCalleeExpression() {
|
||||||
return expression;
|
return calleeExpression;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -345,8 +346,7 @@ public class ControlStructureTypingUtils {
|
|||||||
if (status.hasErrorInConstrainingTypes()) {
|
if (status.hasErrorInConstrainingTypes()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
JetExpression expression = call.getCalleeExpression();
|
JetExpression expression = (JetExpression) call.getCallElement();
|
||||||
if (expression == null) return;
|
|
||||||
if (status.hasOnlyErrorsFromPosition(ConstraintPosition.EXPECTED_TYPE_POSITION) || status.hasConflictingConstraints()) {
|
if (status.hasOnlyErrorsFromPosition(ConstraintPosition.EXPECTED_TYPE_POSITION) || status.hasConflictingConstraints()) {
|
||||||
expression.accept(checkTypeVisitor, new CheckTypeContext(trace, data.expectedType));
|
expression.accept(checkTypeVisitor, new CheckTypeContext(trace, data.expectedType));
|
||||||
return;
|
return;
|
||||||
|
|||||||
+1
-1
@@ -115,7 +115,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
}
|
}
|
||||||
JetBlockExpression thenBlock = JetPsiFactory.wrapInABlock(thenBranch);
|
JetBlockExpression thenBlock = JetPsiFactory.wrapInABlock(thenBranch);
|
||||||
JetBlockExpression elseBlock = JetPsiFactory.wrapInABlock(elseBranch);
|
JetBlockExpression elseBlock = JetPsiFactory.wrapInABlock(elseBranch);
|
||||||
Call callForIf = createCallForSpecialConstruction(ifExpression, Lists.newArrayList(thenBlock, elseBlock));
|
Call callForIf = createCallForSpecialConstruction(ifExpression, ifExpression, Lists.newArrayList(thenBlock, elseBlock));
|
||||||
MutableDataFlowInfoForArguments dataFlowInfoForArguments =
|
MutableDataFlowInfoForArguments dataFlowInfoForArguments =
|
||||||
createDataFlowInfoForArgumentsForIfCall(callForIf, thenInfo, elseInfo);
|
createDataFlowInfoForArgumentsForIfCall(callForIf, thenInfo, elseInfo);
|
||||||
ResolvedCall<FunctionDescriptor> resolvedCall = components.controlStructureTypingUtils.resolveSpecialConstructionAsCall(
|
ResolvedCall<FunctionDescriptor> resolvedCall = components.controlStructureTypingUtils.resolveSpecialConstructionAsCall(
|
||||||
|
|||||||
Reference in New Issue
Block a user