lua-users home
lua-l archive

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


On Mon, 22 Jul 2019, 16:57 Sergey Kovalev, <kovserg33@gmail.com> wrote:
Why upvalues cause no error?

local b="upvalue"

function test()
  local print=print
  do <erroronfreename>
    print("b=",b) -- wtf? no error
  end
end

test()


This is a mean to catch typos, not to write "Pure functions". I.e. it is designed to catch something like:

local anupvalue="upvalue"

function test()
  local print=print
  do <erroronfreename>
    print("anupvalue=",AnUpvalue) -- error
  end
end

test()

Yes, this is already covered by static.lua, but at runtime.

I think that you can avoid upvalues too with small changes. I tryed to do it in the attached patch, but since it was not my goal, I performed very minimal tests only. Please note:

- I kept the <erroronfreename> attribute, also if an upvalue name is not a free name
- _ENV is an upvalue, so you can no more access it anymore (copy it to a local if you need).

Attachment: error_on_free_name_and_upvalue_proof_of_concept.diff
Description: Binary data