'Resolve the type inference for \'elem\' at \'scoperef\'.'

def _hit_from_variable_type_inference(self, elem, scoperef):

    citdl = elem.get('citdl')
    if (not citdl):
        raise CodeIntelError(('no    type-inference    info    for    %r' % elem))
    if ((citdl == 'array') and (self.trg.type == 'array-members')):
        self.log('_hit_from_variable_type_inference::    elem    %r    is    an    array', elem)
        return (elem, scoperef)
    self.log("_hit_from_variable_type_inference::    resolve    '%s'    type    inference    for    %r:", citdl, elem)
    if ((citdl == elem.get('name')) and (elem.tag == 'variable')):
        parent_elem = self._elem_from_scoperef(scoperef)
        if (parent_elem is not None):
            sibling_matches = [x for x in parent_elem.getchildren() if ((x.get('name') == citdl) and (x.tag != 'variable'))]
            if sibling_matches:
                return (sibling_matches[0], scoperef)
        scoperef = self.parent_scoperef_from_scoperef(scoperef)
    variable_namespace = elem.get('namespace')
    if (variable_namespace and (scoperef[0] is not None)):
        self.log('_hit_from_variable_type_inference::    variable    was    defined    in    namespace    %r', variable_namespace)
        blob = scoperef[0]
        ns_elem = blob.names.get(variable_namespace)
        if (ns_elem is not None):
            try:
                hit = self._hit_from_citdl(citdl, (blob, [variable_namespace]))
                if (hit is not None):
                    return hit
            except:
                self.log('_hit_from_variable_type_inference::    %r    not    found    in    namespace    %r', citdl, variable_namespace)
    return self._hit_from_citdl(citdl, scoperef)
