erde-lang / erde

A programming language that compiles to Lua.
https://erde-lang.github.io
MIT License
39 stars 4 forks source link

Global declarations override local declarations #15

Closed bsuth closed 1 year ago

bsuth commented 1 year ago

Global declarations should directly mutate _G. Currently, the compiled code simply adds or remove the local keyword, which is not sufficient as may simply be reassigning local variables:

local a = 1
global a = 2
print(a) -- 2, should be 1 since local scope should be favored
print(_G.a) -- nil
local function test() {
  return 2
}

global function test() {
  return 1
}

print(test()) -- 1
print(_G.test) -- nil
bsuth commented 1 year ago

fixed by https://github.com/erde-lang/erde/commit/2daff444d095c8a113f9803b524455be4462c45b