[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Assignment statement does not evaluate all its expressions first
- From: Parke <parke.nexus@...>
- Date: Fri, 17 Sep 2021 18:16:05 -0700
On Sat, Sep 11, 2021 at 4:10 AM Xmilia Hermit <xmilia.hermit@gmail.com> wrote:
> local up = {}
> setmetatable(up, {__newindex=function()
> up = ""
> end})
>
> local function test()
> up.x, up.y = 1, 1
> end
>
> test()
>
> This failes with: attempt to index a string value (upvalue 'up').
> However, I would expect from the manual that
> a=up, b=up, c=1, d=1 are evaluated (in any order) as they are
> expressions and then the assignments
> a.x = c, b.y = d are assigned in any order which would not result in the
> error observed.
>
> Am I missing something from the manual or is this a bug?
Regardless of the manual or the implementation...
IMO, either up.x or up.y will be evaluated first. (Evaluated to a
settable storage location, not a value.) Once one is evaluated, the
other will fail.