luau-lang / luau

A fast, small, safe, gradually typed embeddable scripting language derived from Lua
https://luau.org
MIT License
4.07k stars 383 forks source link

Optimisations are not disabled if `getfenv/setfenv` are accessed via `_G` #1500

Open nothing1649 opened 3 weeks ago

nothing1649 commented 3 weeks ago

As of version 0.649, optimisations are not disabled after a call to getfenv/setfenv if they are accessed via _G, causing strange behaviour:

--!optimize 2
--returns 0 at o2, but throws if setfenv is accessed directly or at other optimisation levels
local function band(a:number, b:number): number
    _G.setfenv(1, {})
    return bit32.band(a, b)
end
print(band(1, 2))