@Nullable
 private static Type getThisTypeForFunction(
     @NotNull FunctionDescriptor functionDescriptor,
     @NotNull MethodContext context,
     @NotNull JetTypeMapper typeMapper) {
   ReceiverParameterDescriptor dispatchReceiver =
       functionDescriptor.getDispatchReceiverParameter();
   if (functionDescriptor instanceof ConstructorDescriptor) {
     return typeMapper.mapType(functionDescriptor);
   } else if (dispatchReceiver != null) {
     return typeMapper.mapType(dispatchReceiver.getType());
   } else if (isFunctionLiteral(functionDescriptor)
       || isLocalFunction(functionDescriptor)
       || isFunctionExpression(functionDescriptor)) {
     return typeMapper.mapType(context.getThisDescriptor());
   } else {
     return null;
   }
 }