@NotNull
  public TypeInfoForCall getQualifiedExpressionExtendedTypeInfo(
      @NotNull JetQualifiedExpression expression,
      @NotNull ResolutionContext context,
      @NotNull ResolveMode resolveMode) {
    // TODO : functions as values
    JetExpression selectorExpression = expression.getSelectorExpression();
    JetExpression receiverExpression = expression.getReceiverExpression();
    JetTypeInfo receiverTypeInfo =
        expressionTypingServices.getTypeInfoWithNamespaces(
            receiverExpression,
            context.scope,
            NO_EXPECTED_TYPE,
            context.dataFlowInfo,
            context.trace);
    JetType receiverType = receiverTypeInfo.getType();
    if (selectorExpression == null) return TypeInfoForCall.create(null, context.dataFlowInfo);
    if (receiverType == null)
      receiverType = ErrorUtils.createErrorType("Type for " + expression.getText());

    context = context.replaceDataFlowInfo(receiverTypeInfo.getDataFlowInfo());

    if (selectorExpression instanceof JetSimpleNameExpression) {
      ConstantUtils.propagateConstantValues(
          expression, context.trace, (JetSimpleNameExpression) selectorExpression);
    }

    TypeInfoForCall selectorReturnTypeInfo =
        getSelectorReturnTypeInfo(
            new ExpressionReceiver(receiverExpression, receiverType),
            expression.getOperationTokenNode(),
            selectorExpression,
            context,
            resolveMode);
    JetType selectorReturnType = selectorReturnTypeInfo.getType();

    // TODO move further
    if (!(receiverType instanceof NamespaceType)
        && expression.getOperationSign() == JetTokens.SAFE_ACCESS) {
      if (selectorReturnType != null
          && !selectorReturnType.isNullable()
          && !KotlinBuiltIns.getInstance().isUnit(selectorReturnType)) {
        if (receiverType.isNullable()) {
          selectorReturnType = TypeUtils.makeNullable(selectorReturnType);
        }
      }
    }

    // TODO : this is suspicious: remove this code?
    if (selectorReturnType != null) {
      context.trace.record(BindingContext.EXPRESSION_TYPE, selectorExpression, selectorReturnType);
    }
    JetTypeInfo typeInfo =
        JetTypeInfo.create(selectorReturnType, selectorReturnTypeInfo.getDataFlowInfo());
    if (resolveMode == ResolveMode.TOP_LEVEL_CALL) {
      DataFlowUtils.checkType(typeInfo.getType(), expression, context, typeInfo.getDataFlowInfo());
    }
    return TypeInfoForCall.create(typeInfo, selectorReturnTypeInfo);
  }
 @NotNull
 private TypeInfoForCall getSelectorReturnTypeInfo(
     @NotNull ReceiverValue receiver,
     @Nullable ASTNode callOperationNode,
     @NotNull JetExpression selectorExpression,
     @NotNull ResolutionContext context,
     @NotNull ResolveMode resolveMode) {
   if (selectorExpression instanceof JetCallExpression) {
     return getCallExpressionTypeInfoForCallWithoutFinalTypeCheck(
         (JetCallExpression) selectorExpression,
         receiver,
         callOperationNode,
         context,
         resolveMode);
   } else if (selectorExpression instanceof JetSimpleNameExpression) {
     return TypeInfoForCall.create(
         getSimpleNameExpressionTypeInfo(
             (JetSimpleNameExpression) selectorExpression, receiver, callOperationNode, context));
   } else if (selectorExpression instanceof JetQualifiedExpression) {
     JetQualifiedExpression qualifiedExpression = (JetQualifiedExpression) selectorExpression;
     JetExpression newReceiverExpression = qualifiedExpression.getReceiverExpression();
     TypeInfoForCall newReceiverTypeInfo =
         getSelectorReturnTypeInfo(
             receiver,
             callOperationNode,
             newReceiverExpression,
             context.replaceExpectedType(NO_EXPECTED_TYPE),
             resolveMode);
     JetType newReceiverType = newReceiverTypeInfo.getType();
     DataFlowInfo newReceiverDataFlowInfo = newReceiverTypeInfo.getDataFlowInfo();
     JetExpression newSelectorExpression = qualifiedExpression.getSelectorExpression();
     if (newReceiverType != null && newSelectorExpression != null) {
       ExpressionReceiver expressionReceiver =
           new ExpressionReceiver(newReceiverExpression, newReceiverType);
       return getSelectorReturnTypeInfo(
           expressionReceiver,
           qualifiedExpression.getOperationTokenNode(),
           newSelectorExpression,
           context.replaceDataFlowInfo(newReceiverDataFlowInfo),
           resolveMode);
     }
   } else {
     context.trace.report(ILLEGAL_SELECTOR.on(selectorExpression, selectorExpression.getText()));
   }
   return TypeInfoForCall.create(null, context.dataFlowInfo);
 }
  @NotNull
  public TypeInfoForCall getCallExpressionTypeInfoForCallWithoutFinalTypeCheck(
      @NotNull JetCallExpression callExpression,
      @NotNull ReceiverValue receiver,
      @Nullable ASTNode callOperationNode,
      @NotNull ResolutionContext context,
      @NotNull ResolveMode resolveMode) {
    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);
    ResolvedCall<FunctionDescriptor> resolvedCall =
        getResolvedCallForFunction(
            call,
            callExpression,
            receiver,
            context.replaceBindingTrace(traceForFunction),
            resolveMode,
            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 TypeInfoForCall.create(null, context.dataFlowInfo);
      }
      JetType type = functionDescriptor.getReturnType();

      return TypeInfoForCall.create(
          type, resolvedCall.getDataFlowInfo(), resolvedCall, call, context, resolveMode);
    }

    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 TypeInfoForCall.create(null, context.dataFlowInfo);
      }
    }
    traceForFunction.commit();
    return TypeInfoForCall.create(null, context.dataFlowInfo);
  }