# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1251285649 -7200
#      Wed Aug 26 13:20:49 2009 +0200
# Node ID 19ad9d65a95e36412adae8a5103b71fb259c76e0
# Parent  71f875e3e2c19d0481e25cd15b66cac517507ef9
Union.locate_subquery now return a 2-uple (select subquery, column index in the subquery)

diff --git a/stmts.py b/stmts.py
--- a/stmts.py
+++ b/stmts.py
@@ -275,21 +275,25 @@
 
     def _locate_subquery(self, col, etype, kwargs):
         if len(self.children) == 1 and not self.children[0].with_:
-            return self.children[0]
+            return self.children[0], col
         for select in self.children:
             term = select.selection[col]
             try:
                 if term.name in select.aliases:
-                    union = select.aliases[term.name].query
-                    return union._locate_subquery(col, etype, kwargs)
+                    alias = select.aliases[term.name]
+                    return alias.query._locate_subquery(alias.colnum, etype,
+                                                        kwargs)
             except AttributeError:
                 pass
             for i, solution in enumerate(select.solutions):
                 if term.get_type(solution, kwargs) == etype:
-                    return select
+                    return select, col
         raise Exception('internal error, %s not found on col %s' % (etype, col))
 
     def locate_subquery(self, col, etype, kwargs=None):
+        """return a select node and associated selection index where root
+        variable at column `col` is of type `etype`
+        """
         try:
             return self._subq_cache[(col, etype)]
         except AttributeError: