Skip to content

Commit

Permalink
Make sure variables aren't spilled in case clauses
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielGavin committed Oct 3, 2024
1 parent 28982c5 commit 4b8678b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/server/analysis.odin
Original file line number Diff line number Diff line change
Expand Up @@ -2870,14 +2870,28 @@ get_locals_stmt :: proc(
get_locals_stmt(file, v.else_stmt, ast_context, document_position)
get_locals_stmt(file, v.body, ast_context, document_position)
case ^Case_Clause:
for stmt in v.body {
get_locals_stmt(file, stmt, ast_context, document_position)
}
get_locals_case_clause(file, v, ast_context, document_position)
case:
//log.debugf("default node local stmt %v", v);
}
}

get_locals_case_clause :: proc(
file: ast.File,
case_clause: ^ast.Case_Clause,
ast_context: ^AstContext,
document_position: ^DocumentPositionContext,
) {
if !(case_clause.pos.offset <= document_position.position &&
document_position.position <= case_clause.end.offset) {
return
}

for stmt in case_clause.body {
get_locals_stmt(file, stmt, ast_context, document_position)
}
}

get_locals_block_stmt :: proc(
file: ast.File,
block: ast.Block_Stmt,
Expand Down
18 changes: 18 additions & 0 deletions tests/completions_test.odin
Original file line number Diff line number Diff line change
Expand Up @@ -2955,3 +2955,21 @@ ast_raw_data_slice_2 :: proc(t: ^testing.T) {

test.expect_completion_details(t, &source, "", {"test.rezz: [^]int"})
}

@(test)
ast_switch_completion_multiple_cases :: proc(t: ^testing.T) {
source := test.Source {
main = `package main
main :: proc() {
switch {
case true:
foozz: int
case false:
fooz{*}
}
}
`,
}

test.expect_completion_details(t, &source, "", {})
}

0 comments on commit 4b8678b

Please sign in to comment.