You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was just bitten by a curious little code generation bug: when using an augmented assignment with the length operator, Lua is generated that doesn't follow the order of operations. It's a bit odd, because the generated Lua does follow the order of operations if the length operator isn't involved. Here's a minimal reproduction:
which, in Lua 5.4.4 Copyright (C) 1994-2022 Lua.org, PUC-Rio, prints this when interpreted:
0
2
This behavior is a bit unexpected, as assignment (including augmented assignment) is supposed to have the lowest precedence in ANSI C (apologies for the C++ ref, but the same table is in my book), and I assume the operators here introduced are supposed to be semantically compatible with that interpretation. Indeed, if that's the case, the count = count - #datum + 1 is incorrect by the standard, and it's in general safe to always convert LHS $= RHS to LHS = LHS $ (RHS) for all operators $.
The text was updated successfully, but these errors were encountered:
Hello!
I was just bitten by a curious little code generation bug: when using an augmented assignment with the length operator, Lua is generated that doesn't follow the order of operations. It's a bit odd, because the generated Lua does follow the order of operations if the length operator isn't involved. Here's a minimal reproduction:
When using
MoonScript version 0.5.0
,moonc
generates this:which, in
Lua 5.4.4 Copyright (C) 1994-2022 Lua.org, PUC-Rio
, prints this when interpreted:This behavior is a bit unexpected, as assignment (including augmented assignment) is supposed to have the lowest precedence in ANSI C (apologies for the C++ ref, but the same table is in my book), and I assume the operators here introduced are supposed to be semantically compatible with that interpretation. Indeed, if that's the case, the
count = count - #datum + 1
is incorrect by the standard, and it's in general safe to always convertLHS $= RHS
toLHS = LHS $ (RHS)
for all operators$
.The text was updated successfully, but these errors were encountered: