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

Unexpected result when modifying a table (wrong safeenv/optimization) #1535

Open khvzak opened 5 days ago

khvzak commented 5 days ago

Initially discovered in https://github.com/mlua-rs/mlua/discussions/485

Easy to reproduce using Luau cli:

$ luau
> state = {i = 0}
> print("before:", state.i); state.i = state.i + 1; print("after: ", state.i);
before: 0
after:  0

Setting optimization level to 0 OR removing lua_setsafeenv call will give right result:

❯ luau -O0
> state = {i = 0}
> print("before:", state.i); state.i = state.i + 1; print("after: ", state.i);
before: 0
after:  1

Luau v0.652