Skip to content

Commit 2b64421

Browse files
authored
ide: fix stack overflow with cte column hover that shadows a table (#786)
1 parent 01c790f commit 2b64421

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

crates/squawk_ide/src/hover.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,4 +1581,18 @@ select a$0 from y;
15811581
╰╴ ─ hover
15821582
");
15831583
}
1584+
1585+
#[test]
1586+
fn hover_on_cte_shadowing_table_with_star() {
1587+
assert_snapshot!(check_hover("
1588+
create table t(a bigint);
1589+
with t as (select * from t)
1590+
select a$0 from t;
1591+
"), @r"
1592+
hover: column public.t.a bigint
1593+
╭▸
1594+
4 │ select a from t;
1595+
╰╴ ─ hover
1596+
");
1597+
}
15841598
}

crates/squawk_ide/src/resolve.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,11 @@ fn resolve_cte_column(
851851
{
852852
let from_table_name =
853853
Name::new(from_name_ref.syntax().text().to_string());
854-
return resolve_cte_column(name_ref, &from_table_name, column_name);
854+
// Skip recursive CTE lookup if the FROM table has the same name as the current CTE
855+
// (CTEs don't shadow themselves in their own definition)
856+
if from_table_name != *cte_name {
857+
return resolve_cte_column(name_ref, &from_table_name, column_name);
858+
}
855859
}
856860
}
857861
}

0 commit comments

Comments
 (0)