lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Lua5.4 introduces the 'const' keyword, that's great. But when I test some cases, I have a question.

I test the code as follow:

```lua

local a<const> = 1

if a == 1 then
        print("hello world")
else
        print("foobar")

end

```

Because the variable 'a' is always be 1.  So I think `if a == 1` should be removed during the compilation stage.

The equivalent code after compilation should be as follows:

```Lua

        print("hello world")

```

But Luac didn't do it.

 I'm curious why Lua didn't do it.

Thanks for your answer.