teal-language / tl

The compiler for Teal, a typed dialect of Lua
MIT License
2.1k stars 108 forks source link

A potential bug with variable shadowing? #545

Closed Calandiel closed 2 years ago

Calandiel commented 2 years ago
global function test()
    local boo: string = "1"

    global boo: number = 1
end

test()
print(boo)

The above translates to this:

function test()
   local boo = "1"

   boo = 1
end

test()
print(boo)

I think taking teal code at a glance, you'd expect the print to output 1, but the lua version will of course output nil instead.

hishamhm commented 2 years ago

Ah, good catch! I think the way to go to fix this is to disallow creating a global in a scope where there is already a local with the same name, thus guaranteeing that valid Teal code matches the Lua semantics for that.