From d36190a5f3b8fa33fe3381771cd1efb9a1335e50 Mon Sep 17 00:00:00 2001 From: zinc Date: Thu, 15 Oct 2026 15:19:17 +0330 Subject: prescan: guess an owned return only from a local declared from new/heap, not a global assigned one (fixes lsp self-check); xref baseline for the new writers --- src/compiler/decl.zc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/decl.zc b/src/compiler/decl.zc index e2c3613..bbde5ba 100644 --- a/src/compiler/decl.zc +++ b/src/compiler/decl.zc @@ -94,8 +94,12 @@ int prescan_maker() { // the guess only makes the function compile as if declared .u; its body is then // checked against that, so a wrong guess is an error, never a silent leak. int prescan_owned(int self) { - int depth = 0, n, k, found = 0, nown = 0; let owned[16]; + int depth = 0, n, k, found = 0, nown = 0, decl = 0; let owned[16]; while (tk != T_EOF) { + // a declaration's name follows a type name, a *, let or a comma; a plain + // assignment (to a global, say) follows ; { or } + int was = decl; + decl = tk == T_ID || (tk == T_OP && (rt.eq_w(tv, "*") || rt.eq_w(tv, ","))); if (is_op(s_lb)) depth++; else if (is_op(s_rb)) { depth--; if (!depth) { next(); return found; } } else if (tk == T_ID && rt.eq_w(tv, "return")) { @@ -107,7 +111,7 @@ int prescan_owned(int self) { } continue; } - else if (tk == T_ID) { + else if (tk == T_ID && was) { n = tv; peek(); if (pk_tk == T_OP && pk_tv == s_eq) { next(); next(); -- cgit v1.2.3