diff options
| author | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-09-10 20:45:03 -0400 |
|---|---|---|
| committer | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-09-10 20:45:55 -0400 |
| commit | 547fdadd808ae6b0bbaaaba17deaaca3582cbc41 (patch) | |
| tree | aa4682983eb675ed28aab038115a1905c369ad6e /src | |
| parent | f3ae71ff7f6e3713e42c9fc65c735babba5caff0 (diff) | |
Correctly resolve comp lits in map keys
Diffstat (limited to 'src')
| -rw-r--r-- | src/server/analysis.odin | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index f19df28..f10ed28 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -1999,18 +1999,36 @@ internal_resolve_comp_literal :: proc( symbol = resolve_proc(ast_context, position_context.value_decl.type) or_return } else if position_context.assign != nil { if len(position_context.assign.lhs) > 0 { - index := 0 - for value, i in position_context.assign.rhs { - if position_in_node(value, position_context.position) { - index = i - break + if position_in_exprs(position_context.assign.lhs, position_context.position) { + for n in position_context.assign.lhs { + if position_in_node(n, position_context.position) { + // check if we're a comp literal of a map key + if index_expr, ok := n.derived.(^ast.Index_Expr); ok { + if s, ok := resolve_proc(ast_context, index_expr.expr); ok { + if value, ok := s.value.(SymbolMapValue); ok { + symbol = resolve_proc(ast_context, value.key) or_return + } + } + } else { + symbol = resolve_proc(ast_context, n) or_return + } + break + } } + } else { + index := 0 + for value, i in position_context.assign.rhs { + if position_in_node(value, position_context.position) { + index = i + break + } + } + // Just to be safe + if index >= len(position_context.assign.lhs) { + index = 0 + } + symbol = resolve_proc(ast_context, position_context.assign.lhs[index]) or_return } - // Just to be safe - if index >= len(position_context.assign.lhs) { - index = 0 - } - symbol = resolve_proc(ast_context, position_context.assign.lhs[index]) or_return } } |