[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Assigning to a constant variable with function definition syntax doesn't error
- From: Francisco Olarte <folarte@...>
- Date: Thu, 17 Jun 2021 18:32:59 +0200
On Thu, Jun 17, 2021 at 5:35 PM Domingo Alvarez Duarte
> Isn't this the general pattern in Lua to always create a new variable
> and shadow any existing one with the same name, without telling anything
> to the user ?
function x() does not create a new variable, it uses a created one (
either local or global, although you may consider the global one as
The problem is:
$ cat u.lua && lua u.lua
local x <const> = nil
function x() end
local y <const> = nil
y = function() end
lua: u.lua:5: attempt to assign to const variable 'y'
Coupled with the definition in 3.4.11
function f () body end
f = function () body end
Which mean they should both pass or fail. No new vars created by the
function lines, which will be the case if "local function" where used.