PlutoLang / Pluto

A superset of Lua 5.4 with a focus on general-purpose programming.
https://pluto-lang.org/docs/Introduction
MIT License
337 stars 20 forks source link

The keyword 'parent' is parsed improperly #885

Closed well-in-that-case closed 2 weeks ago

well-in-that-case commented 2 weeks ago

Issues

parent cannot be used as an identifier with implicit globals: (stack corruption & improper parsing)

parent = 5 -- bad

assert(_G["parent"] == 5) -- good
assert(_G.parent == 5) -- good
assert(parent == 5) -- bad

parent = nil

parent cannot be used as a local function identifier, but can be used as a local identifier: (inconsistency)

local function parent() -- bad
    return 5
end

local parent = function () -- good
    return 5
end

print(parent())

parent should also have its purpose narrowed to within classes at a minimum. There is no logic checking for this.

Usefulness, even after it's fixed

In exchange for disallowing 'parent' to be properly used as an identifier inside of classes (or at all, currently), you can use it as a sometimes-shorthand to access the parent whose name you already know and who you can already access through the __parent field.