def merge_with(self, other: 'Symbol', docnames: List[str], env: 'BuildEnvironment') -> None:
    if Symbol.debug_lookup:
        Symbol.debug_indent += 1
        Symbol.debug_print('merge_with:')
    assert (other is not None)

    def unconditionalAdd(self, otherChild):
        self._children.append(otherChild)
        otherChild.parent = self
        otherChild._assert_invariants()
    if Symbol.debug_lookup:
        Symbol.debug_indent += 1
    for otherChild in other._children:
        if Symbol.debug_lookup:
            Symbol.debug_print('otherChild:\n', otherChild.to_string(Symbol.debug_indent))
            Symbol.debug_indent += 1
        if otherChild.isRedeclaration:
            unconditionalAdd(self, otherChild)
            if Symbol.debug_lookup:
                Symbol.debug_print('isRedeclaration')
                Symbol.debug_indent -= 1
            continue
        candiateIter = self._find_named_symbols(identOrOp=otherChild.identOrOp, templateParams=otherChild.templateParams, templateArgs=otherChild.templateArgs, templateShorthand=False, matchSelf=False, recurseInAnon=False, correctPrimaryTemplateArgs=False, searchInSiblings=False)
        candidates = list(candiateIter)
        if Symbol.debug_lookup:
            Symbol.debug_print('raw candidate symbols:', len(candidates))
        symbols = [s for s in candidates if (not s.isRedeclaration)]
        if Symbol.debug_lookup:
            Symbol.debug_print('non-duplicate candidate symbols:', len(symbols))
        if (len(symbols) == 0):
            unconditionalAdd(self, otherChild)
            if Symbol.debug_lookup:
                Symbol.debug_indent -= 1
            continue
        ourChild = None
        if (otherChild.declaration is None):
            if Symbol.debug_lookup:
                Symbol.debug_print('no declaration in other child')
            ourChild = symbols[0]
        else:
            queryId = otherChild.declaration.get_newest_id()
            if Symbol.debug_lookup:
                Symbol.debug_print('queryId:  ', queryId)
            for symbol in symbols:
                if (symbol.declaration is None):
                    if Symbol.debug_lookup:
                        Symbol.debug_print('empty candidate')
                    ourChild = symbol
                    continue
                candId = symbol.declaration.get_newest_id()
                if Symbol.debug_lookup:
                    Symbol.debug_print('candidate:', candId)
                if (candId == queryId):
                    ourChild = symbol
                    break
        if Symbol.debug_lookup:
            Symbol.debug_indent -= 1
        if (ourChild is None):
            unconditionalAdd(self, otherChild)
            continue
        if (otherChild.declaration and (otherChild.docname in docnames)):
            if (not ourChild.declaration):
                ourChild._fill_empty(otherChild.declaration, otherChild.docname)
            elif (ourChild.docname != otherChild.docname):
                name = str(ourChild.declaration)
                msg = __("Duplicate declaration, also defined in '%s'.\nDeclaration is '%s'.")
                msg = (msg % (ourChild.docname, name))
                logger.warning(msg, location=otherChild.docname)
            else:
                msg = 'Internal C++ domain error during symbol merging.\n'
                msg += ('ourChild:\n' + ourChild.to_string(1))
                msg += ('\notherChild:\n' + otherChild.to_string(1))
                logger.warning(msg, location=otherChild.docname)
        ourChild.merge_with(otherChild, docnames, env)
    if Symbol.debug_lookup:
        Symbol.debug_indent -= 2
def merge_with(self, other: 'Symbol', docnames: List[str], env: 'BuildEnvironment') -> None:
    if Symbol.debug_lookup:
        Symbol.debug_indent += 1
        Symbol.debug_print('merge_with:')
    assert (other is not None)

    def unconditionalAdd(self, otherChild):
        self._children.append(otherChild)
        otherChild.parent = self
        otherChild._assert_invariants()
    if Symbol.debug_lookup:
        Symbol.debug_indent += 1
    for otherChild in other._children:
        if Symbol.debug_lookup:
            Symbol.debug_print('otherChild:\n', otherChild.to_string(Symbol.debug_indent))
            Symbol.debug_indent += 1
        if otherChild.isRedeclaration:
            unconditionalAdd(self, otherChild)
            if Symbol.debug_lookup:
                Symbol.debug_print('isRedeclaration')
                Symbol.debug_indent -= 1
            continue
        candiateIter = self._find_named_symbols(identOrOp=otherChild.identOrOp, templateParams=otherChild.templateParams, templateArgs=otherChild.templateArgs, templateShorthand=False, matchSelf=False, recurseInAnon=False, correctPrimaryTemplateArgs=False, searchInSiblings=False)
        candidates = list(candiateIter)
        if Symbol.debug_lookup:
            Symbol.debug_print('raw candidate symbols:', len(candidates))
        symbols = [s for s in candidates if (not s.isRedeclaration)]
        if Symbol.debug_lookup:
            Symbol.debug_print('non-duplicate candidate symbols:', len(symbols))
        if (len(symbols) == 0):
            unconditionalAdd(self, otherChild)
            if Symbol.debug_lookup:
                Symbol.debug_indent -= 1
            continue
        ourChild = None
        if (otherChild.declaration is None):
            if Symbol.debug_lookup:
                Symbol.debug_print('no declaration in other child')
            ourChild = symbols[0]
        else:
            queryId = otherChild.declaration.get_newest_id()
            if Symbol.debug_lookup:
                Symbol.debug_print('queryId:  ', queryId)
            for symbol in symbols:
                if (symbol.declaration is None):
                    if Symbol.debug_lookup:
                        Symbol.debug_print('empty candidate')
                    ourChild = symbol
                    continue
                candId = symbol.declaration.get_newest_id()
                if Symbol.debug_lookup:
                    Symbol.debug_print('candidate:', candId)
                if (candId == queryId):
                    ourChild = symbol
                    break
        if Symbol.debug_lookup:
            Symbol.debug_indent -= 1
        if (ourChild is None):
            unconditionalAdd(self, otherChild)
            continue
        if (otherChild.declaration and (otherChild.docname in docnames)):
            if (not ourChild.declaration):
                ourChild._fill_empty(otherChild.declaration, otherChild.docname)
            elif (ourChild.docname != otherChild.docname):
                name = str(ourChild.declaration)
                msg = __("Duplicate declaration, also defined in '%s'.\nDeclaration is '%s'.")
                msg = (msg % (ourChild.docname, name))
                logger.warning(msg, location=otherChild.docname)
            else:
                msg = 'Internal C++ domain error during symbol merging.\n'
                msg += ('ourChild:\n' + ourChild.to_string(1))
                msg += ('\notherChild:\n' + otherChild.to_string(1))
                logger.warning(msg, location=otherChild.docname)
        ourChild.merge_with(otherChild, docnames, env)
    if Symbol.debug_lookup:
        Symbol.debug_indent -= 2