Example #1
0
  @NotNull
  private <D extends CallableDescriptor, F extends D>
      OverloadResolutionResultsImpl<F> performResolution(
          @NotNull ResolutionTask<D, F> task, @NotNull CallTransformer<D, F> callTransformer) {

    for (ResolutionCandidate<D> resolutionCandidate : task.getCandidates()) {
      TemporaryBindingTrace candidateTrace =
          TemporaryBindingTrace.create(task.trace, "trace to resolve candidate");
      Collection<CallCandidateResolutionContext<D>> contexts =
          callTransformer.createCallContexts(resolutionCandidate, task, candidateTrace);
      for (CallCandidateResolutionContext<D> context : contexts) {

        candidateResolver.performResolutionForCandidateCall(context, task);

        /* important for 'variable as function case': temporary bind reference to descriptor (will be rewritten)
        to have a binding to variable while 'invoke' call resolve */
        task.tracing.bindReference(context.candidateCall.getTrace(), context.candidateCall);

        Collection<ResolvedCallWithTrace<F>> calls =
            callTransformer.transformCall(context, this, task);

        for (ResolvedCallWithTrace<F> call : calls) {
          task.tracing.bindReference(call.getTrace(), call);
          task.tracing.bindResolvedCall(call.getTrace(), call);
          task.getResolvedCalls().add(call);
        }
      }
    }

    OverloadResolutionResultsImpl<F> results =
        ResolutionResultsHandler.INSTANCE.computeResultAndReportErrors(
            task.trace, task.tracing, task.getResolvedCalls());
    if (!results.isSingleResult() && !results.isIncomplete()) {
      argumentTypeResolver.checkTypesWithNoCallee(task.toBasic());
    }
    return results;
  }
  @NotNull
  public <D extends CallableDescriptor> JetTypeInfo getCallExpressionTypeInfoWithoutFinalTypeCheck(
      @NotNull JetCallExpression callExpression,
      @NotNull ReceiverValue receiver,
      @Nullable ASTNode callOperationNode,
      @NotNull ResolutionContext context,
      @NotNull ResolveMode resolveMode,
      @NotNull ResolutionResultsCache resolutionResultsCache) {
    boolean[] result = new boolean[1];
    Call call = CallMaker.makeCall(receiver, callOperationNode, callExpression);

    TemporaryBindingTrace traceForFunction =
        TemporaryBindingTrace.create(
            context.trace, "trace to resolve as function call", callExpression);
    ResolvedCallWithTrace<FunctionDescriptor> resolvedCall =
        getResolvedCallForFunction(
            call,
            callExpression,
            receiver,
            context.replaceBindingTrace(traceForFunction),
            resolveMode,
            resolutionResultsCache,
            result);
    if (result[0]) {
      FunctionDescriptor functionDescriptor =
          resolvedCall != null ? resolvedCall.getResultingDescriptor() : null;
      traceForFunction.commit();
      if (callExpression.getValueArgumentList() == null
          && callExpression.getFunctionLiteralArguments().isEmpty()) {
        // there are only type arguments
        boolean hasValueParameters =
            functionDescriptor == null || functionDescriptor.getValueParameters().size() > 0;
        context.trace.report(
            FUNCTION_CALL_EXPECTED.on(callExpression, callExpression, hasValueParameters));
      }
      if (functionDescriptor == null) {
        return JetTypeInfo.create(null, context.dataFlowInfo);
      }
      JetType type = functionDescriptor.getReturnType();

      return JetTypeInfo.create(type, resolvedCall.getDataFlowInfo());
    }

    JetExpression calleeExpression = callExpression.getCalleeExpression();
    if (calleeExpression instanceof JetSimpleNameExpression
        && callExpression.getTypeArgumentList() == null) {
      TemporaryBindingTrace traceForVariable =
          TemporaryBindingTrace.create(
              context.trace, "trace to resolve as variable with 'invoke' call", callExpression);
      JetType type =
          getVariableType(
              (JetSimpleNameExpression) calleeExpression,
              receiver,
              callOperationNode,
              context.replaceBindingTrace(traceForVariable),
              result);
      if (result[0]) {
        traceForVariable.commit();
        context.trace.report(
            FUNCTION_EXPECTED.on(
                (JetReferenceExpression) calleeExpression,
                calleeExpression,
                type != null ? type : ErrorUtils.createErrorType("")));
        return JetTypeInfo.create(null, context.dataFlowInfo);
      }
    }
    traceForFunction.commit();
    return JetTypeInfo.create(null, context.dataFlowInfo);
  }