diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2024-10-03 21:09:40 +0200 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2024-10-03 21:09:40 +0200 |
| commit | 4b8678b8f6b54e3c8dbbbd943228e6b9c919f330 (patch) | |
| tree | 2ff883720f8a12ebc92f3b55519b9074be839e33 /src/server | |
| parent | 28982c543bf43eb3378cc47b7aa33c405f7bc6b2 (diff) | |
Make sure variables aren't spilled in case clauses
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/analysis.odin | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index ee73f16..b27f6b7 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -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, |