def align_indexes(self) -> None:
        """Compute all aligned indexes and their corresponding coordinate variables."""

        aligned_indexes: dict[MatchingIndexKey, Index] = {}
        aligned_index_vars: dict[MatchingIndexKey, dict[Hashable, Variable]] = {}
        reindex: dict[MatchingIndexKey, bool] = {}
        new_indexes: dict[Hashable, Index] = {}
        new_index_vars: dict[Hashable, Variable] = {}

        def update_dicts(
            key: MatchingIndexKey,
            idx: Index,
            idx_vars: dict[Hashable, Variable],
            need_reindex: bool,
        ):
            reindex[key] = need_reindex
            aligned_indexes[key] = idx
            aligned_index_vars[key] = idx_vars

            for name, var in idx_vars.items():
                if name in new_indexes:
                    other_idx = new_indexes[name]
                    other_var = new_index_vars[name]
                    raise AlignmentError(
                        f"cannot align objects on coordinate {name!r} because of conflicting indexes\n"
                        f"first index: {idx!r}\nsecond index: {other_idx!r}\n"
                        f"first variable: {var!r}\nsecond variable: {other_var!r}\n"
                    )
                new_indexes[name] = idx
                new_index_vars[name] = var

        for key, matching_indexes in self.all_indexes.items():
            matching_index_vars = self.all_index_vars[key]
            dims = {d for coord in matching_index_vars[0].values() for d in coord.dims}
            index_cls = key[1]

            if self.join == "override":
                joined_index = matching_indexes[0]
                joined_index_vars = matching_index_vars[0]
                need_reindex = False
            elif key in self.indexes:
                joined_index = self.indexes[key]
                joined_index_vars = self.index_vars[key]
                cmp_indexes = list(
                    zip(
                        [joined_index] + matching_indexes,
                        [joined_index_vars] + matching_index_vars,
                        strict=True,
                    )
                )
                need_reindex = self._need_reindex(dims, cmp_indexes)
            else:
                if len(matching_indexes) > 1:
                    need_reindex = self._need_reindex(
                        dims,
                        list(zip(matching_indexes, matching_index_vars, strict=True)),
                    )
                else:
                    need_reindex = False
                if need_reindex:
                    if self.join == "exact":
                        raise AlignmentError(
                            "cannot align objects with join='exact' where "
                            "index/labels/sizes are not equal along "
                            "these coordinates (dimensions): "
                            + ", ".join(f"{name!r} {dims!r}" for name, dims in key[0])
                        )
                    joiner = self._get_index_joiner(index_cls)
                    joined_index = joiner(matching_indexes)
                    if self.join == "left":
                        joined_index_vars = matching_index_vars[0]
                    elif self.join == "right":
                        joined_index_vars = matching_index_vars[-1]
                    else:
                        joined_index_vars = joined_index.create_variables()
                else:
                    joined_index = matching_indexes[0]
                    joined_index_vars = matching_index_vars[0]

            update_dicts(key, joined_index, joined_index_vars, need_reindex)

        # Explicitly provided indexes that are not found in objects to align
        # may relate to unindexed dimensions so we add them too
        for key, idx in self.indexes.items():
            if key not in aligned_indexes:
                index_vars = self.index_vars[key]
                update_dicts(key, idx, index_vars, False)

        self.aligned_indexes = aligned_indexes
        self.aligned_index_vars = aligned_index_vars
        self.reindex = reindex
        self.new_indexes = Indexes(new_indexes, new_index_vars)
Compute all aligned indexes and their corresponding coordinate variables.
xarray/structure/alignment.py