src/NFun/Tic/SolvingFunctions.cs
/// <summary>
/// Merge two nodes. Both of them become equiualent.
///
/// In complex situation, 'secondary' node becomes reference to 'main' node, if it is possible
/// </summary>
Merge two nodes. Both of them become equiualent.

In complex situation, 'secondary' node becomes reference to 'main' node, if it is possible
Merge two nodes . Both of them become equiualent . In complex situation ' secondary ' node becomes reference to ' main ' node if it is possible
public static void MergeInplace(TicNode main, TicNode secondary) {
        if (main == secondary)
            return;
        if (main.State is StateRefTo)
        {
            var nonreferenceMain = main.GetNonReference();
            var nonreferenceSecondary = secondary.GetNonReference();
            MergeInplace(nonreferenceMain, nonreferenceSecondary);
            return;
        }
        if (secondary.GetNonReference() == main)
            return;
        var res = GetMergedStateOrNull(main.State, secondary.State);
        if (res == null)
            throw TicErrors.CannotMerge(main, secondary);
        main.State = res;
        if (res is ITypeState t && t.IsSolved)
        {
            secondary.State = res;
            return;
        }
        main.AddAncestors(secondary.Ancestors.Where(a => a != main));
        secondary.ClearAncestors();
        secondary.State = new StateRefTo(main);
    }
public static void MergeInplace ( TicNode main , TicNode secondary ) { if ( main == secondary ) return ; if ( main . State is StateRefTo ) { var nonreferenceMain = main . GetNonReference ( ) ; var nonreferenceSecondary = secondary . GetNonReference ( ) ; MergeInplace ( nonreferenceMain , nonreferenceSecondary ) ; return ; } if ( secondary . GetNonReference ( ) == main ) return ; var res = GetMergedStateOrNull ( main . State , secondary . State ) ; if ( res == null ) throw TicErrors . CannotMerge ( main , secondary ) ; main . State = res ; if ( res is ITypeState t && t . IsSolved ) { secondary . State = res ; return ; } main . AddAncestors ( secondary . Ancestors . Where ( a => a != main ) ) ; secondary . ClearAncestors ( ) ; secondary . State = new StateRefTo ( main ) ; }
Merge two nodes.
Merge two nodes .
main
TicNode
secondary
TicNode