Skip to content

Commit 77bd8ec

Browse files
committed
fix(ocaml): attribute in-body calls to the outermost function, not nested lets
OCaml's def walk does not descend into function bodies, so it emits a node only for the OUTERMOST value_definition (the top-level function). The unified walk, however, descends to find calls and pushed a SCOPE_FUNC for every value_definition it met — including a nested local `let x = e in ...`, which is also a value_definition but has no node. An in-body call then attributed to that nodeless local binding, so its CALLS edge sourced to neither a Function nor the Module (callable=0, module=0 in the breadth invariant). Push a function scope only for the outermost value_definition (none already on the scope stack) for OCaml, so in-body calls attribute to the top-level function the def walk actually emitted. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent f473119 commit 77bd8ec

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

‎internal/cbm/extract_unified.c‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,9 +1110,26 @@ static bool is_export_of_declaration(TSNode node) {
11101110
static void push_boundary_scopes(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec *spec,
11111111
WalkState *state, uint32_t depth) {
11121112
if (spec->function_node_types && cbm_kind_in_set(node, spec->function_node_types)) {
1113-
const char *fqn = compute_func_qn(ctx, node, spec, state);
1114-
if (fqn) {
1115-
push_scope(state, SCOPE_FUNC, depth, fqn);
1113+
/* OCaml: a nested local `let x = e in ...` is itself a value_definition,
1114+
* but the def walk does not descend into function bodies, so it emits no
1115+
* node for it. Pushing a func scope here would attribute in-body calls to
1116+
* that nodeless local binding — the CALLS edge then sources to neither a
1117+
* Function nor the Module. Only the OUTERMOST value_definition pushes a
1118+
* scope (none already on the stack), matching what the def walk extracts. */
1119+
bool skip_nested = false;
1120+
if (ctx->language == CBM_LANG_OCAML) {
1121+
for (int i = 0; i < state->scope_top; i++) {
1122+
if (state->scopes[i].kind == SCOPE_FUNC) {
1123+
skip_nested = true;
1124+
break;
1125+
}
1126+
}
1127+
}
1128+
if (!skip_nested) {
1129+
const char *fqn = compute_func_qn(ctx, node, spec, state);
1130+
if (fqn) {
1131+
push_scope(state, SCOPE_FUNC, depth, fqn);
1132+
}
11161133
}
11171134
} else if (spec->class_node_types && cbm_kind_in_set(node, spec->class_node_types)) {
11181135
const char *cqn = compute_class_qn(ctx, node, state);

0 commit comments

Comments
 (0)