Compute binary expression more accurately
Right now, the check to verify if a metamethod can be invoked in a binary expression is a little to strict. In Lua 5.1 and Roblox, most operators will call a metamethod:
| operator | metamethod |
|---|---|
+ |
__add |
- |
__sub |
* |
__mul |
/ |
__div |
% |
__mod |
^ |
__pow |
.. |
__concat |
== |
__eq |
< |
__lt |
<= |
__le |
However, the binary operators and and or cannot call any metamethod so expressions like false and var cannot have any side effects. Another simpler way to reason about this is that depending on the value of the left side, the expression on the right side may not even be evaluated (which makes a bit of sense to why there is no metamethod for and or or).
This means that an expression like this:
return false and var
Can be converted into:
return false
Edited by jeparlefrancais