From cf52e92920563f872047fd4779db2e836a9ea5ee Mon Sep 17 00:00:00 2001 From: carlos-alm Date: Tue, 4 Aug 2026 02:49:23 -0600 Subject: [PATCH] fix(lua): tag literal-key bracket-index calls as computed-literal (docs check acknowledged) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lua's t["handler"]() bracket-index call with a string-literal key resolved correctly but emitted a plain, untagged Call — identical in shape to a static t.handler() call. This diverged from ADR-002's Track A/B taxonomy: JS's obj["method"]() convention (extractSubscriptCallInfo) tags the same pattern dynamic: true, dynamicKind: 'computed-literal' so it stays distinguishable from static dispatch. Lua table indexing has no structural difference from JS member access here — both t.handler() and t["handler"]() are equally subject to metatable __index redirection — so there's no language-specific reason to diverge from JS's convention. Tag both engines to match. Closes #2042 Impact: 1 functions changed, 2 affected --- crates/codegraph-core/src/extractors/lua.rs | 31 +++++++++++++++------ src/extractors/lua.ts | 11 ++++++++ tests/parsers/lua.test.ts | 21 +++++++++++--- 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/crates/codegraph-core/src/extractors/lua.rs b/crates/codegraph-core/src/extractors/lua.rs index a03a5cb2c..bc921f64c 100644 --- a/crates/codegraph-core/src/extractors/lua.rs +++ b/crates/codegraph-core/src/extractors/lua.rs @@ -296,11 +296,23 @@ fn handle_lua_function_call(node: &Node, source: &[u8], symbols: &mut FileSymbol } if let Some(k) = key { if k.kind() == "string" || k.kind() == "string_literal" { + // t["handler"]() — literal-key bracket index; statically + // resolvable to the same target as t.handler(), so it still + // resolves to a normal edge. Tagged `computed-literal` (ADR-002 + // Track A) to match JS's extractSubscriptCallInfo convention for + // obj["method"]() and make the call visible to dynamic_kind-based + // queries — see issue #2042. Lua table indexing has no structural + // difference from JS member access here: both `t.handler()` and + // `t["handler"]()` are equally subject to metatable `__index` + // redirection, so there's no Lua-specific reason the literal-key + // form should be treated as more "static" than JS's equivalent. let raw = node_text(&k, source); let call_name = raw.trim_matches(|c| c == '\'' || c == '"').to_string(); symbols.calls.push(Call { name: call_name, line: start_line(node), + dynamic: Some(true), + dynamic_kind: Some("computed-literal".to_string()), receiver: table.map(|t| node_text(&t, source).to_string()), ..Default::default() }); @@ -464,20 +476,23 @@ mod tests { #[test] fn resolves_bracket_index_call_with_string_literal_key_directly() { + // Resolves to the same target as `t.handler()`, but tagged Track A + // `computed-literal` (#2042) to match JS's `obj["method"]()` convention + // instead of looking identical to a static `t.handler()` call. let s = parse_lua("t[\"handler\"]()"); - assert!(s - .calls - .iter() - .any(|c| c.name == "handler" && c.receiver.as_deref() == Some("t") && c.dynamic.is_none())); + assert!(s.calls.iter().any(|c| c.name == "handler" + && c.receiver.as_deref() == Some("t") + && c.dynamic == Some(true) + && c.dynamic_kind.as_deref() == Some("computed-literal"))); } #[test] fn resolves_bracket_index_call_with_single_quoted_string_literal_key_directly() { let s = parse_lua("t['handler']()"); - assert!(s - .calls - .iter() - .any(|c| c.name == "handler" && c.receiver.as_deref() == Some("t"))); + assert!(s.calls.iter().any(|c| c.name == "handler" + && c.receiver.as_deref() == Some("t") + && c.dynamic == Some(true) + && c.dynamic_kind.as_deref() == Some("computed-literal"))); } #[test] diff --git a/src/extractors/lua.ts b/src/extractors/lua.ts index 3a510eb94..b85af41ce 100644 --- a/src/extractors/lua.ts +++ b/src/extractors/lua.ts @@ -371,11 +371,22 @@ function handleLuaFunctionCall(node: TreeSitterNode, ctx: ExtractorOutput): void // (undecidable statically — flagged `computed-key`). Mirrors // handle_lua_function_call's `bracket_index_expression` arm in // crates/codegraph-core/src/extractors/lua.rs. + // + // The literal-key case (`t["handler"]()`) is tagged `computed-literal` + // (ADR-002 Track A — resolvable) to match JS's extractSubscriptCallInfo + // convention for `obj["method"]()`, making it visible to dynamic_kind- + // based queries instead of looking identical to a static `t.handler()` + // call (issue #2042). Lua table indexing is not structurally different + // from JS member access here — both `t.handler()` and `t["handler"]()` + // are equally subject to metatable `__index` redirection — so there is + // no Lua-specific reason to diverge from JS's convention. const table = nameNode.childForFieldName('table'); const key = nameNode.childForFieldName('field'); if (key) { if (LUA_STRING_NODE_TYPES.has(key.type)) { call.name = key.text.replace(/^['"]|['"]$/g, ''); + call.dynamic = true; + call.dynamicKind = 'computed-literal'; if (table) call.receiver = table.text; } else { const dynamicCall: Call = { diff --git a/tests/parsers/lua.test.ts b/tests/parsers/lua.test.ts index 58520b210..9c4e47d39 100644 --- a/tests/parsers/lua.test.ts +++ b/tests/parsers/lua.test.ts @@ -216,18 +216,31 @@ string.format("%s", name)`); ); }); - it('resolves a bracket-index call with a string-literal key directly', () => { + it('resolves a bracket-index call with a string-literal key directly, tagged computed-literal', () => { + // Resolves to the same target as `t.handler()`, but tagged Track A + // `computed-literal` (#2042) to match JS's `obj["method"]()` convention + // instead of looking identical to a static `t.handler()` call. const symbols = parseLua(`t["handler"]()`); expect(symbols.calls).toContainEqual( - expect.objectContaining({ name: 'handler', receiver: 't' }), + expect.objectContaining({ + name: 'handler', + receiver: 't', + dynamic: true, + dynamicKind: 'computed-literal', + }), ); expect(symbols.calls.some((c) => c.dynamicKind === 'computed-key')).toBe(false); }); - it('resolves a bracket-index call with a single-quoted string-literal key directly', () => { + it('resolves a bracket-index call with a single-quoted string-literal key directly, tagged computed-literal', () => { const symbols = parseLua(`t['handler']()`); expect(symbols.calls).toContainEqual( - expect.objectContaining({ name: 'handler', receiver: 't' }), + expect.objectContaining({ + name: 'handler', + receiver: 't', + dynamic: true, + dynamicKind: 'computed-literal', + }), ); });