Skip to content

fix: local function declarations#152

Open
davydog187 wants to merge 1 commit intomainfrom
function-local-declaration
Open

fix: local function declarations#152
davydog187 wants to merge 1 commit intomainfrom
function-local-declaration

Conversation

@davydog187
Copy link
Contributor

@davydog187 davydog187 commented Feb 18, 2026

Pulled from #142
Closes #144

FuncDecl Local Assignment ⭐

Fixed function f() syntax to properly update local variables:

  • function f() now correctly updates local f when one exists in scope
  • Scope resolution marks assignment target in var_map at declaration time
  • Prevents future locals from incorrectly affecting earlier code during codegen
  • Fixes common Lua pattern where local f = function()... is followed by function f()

Example fixed pattern:

local f = function(x) return "first" end
-- Later redefine f
function f(x) return "second" end
-- f now correctly refers to "second"

FuncDecl Fix:

  • Scope resolution checks if local exists at FuncDecl position
  • Stores target as {:func_decl_target, decl} in var_map
  • Codegen uses this marker instead of checking ctx.scope.locals (which contains all function-scope locals)

@davydog187 davydog187 changed the title fix: local funciton declarations fix: local function declarations Feb 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

local function declarations are silently dropped

1 participant

Comments