Describe the bug
The DivExpression in ast.lua has a simplify argument which will perform the division and store the result if both left and right-hand side of the expression is a constant. This works great in all cases except when dividing by 0.
print(1/0) -- inf
print(-1/0) -- -inf
print(0/0) -- nan
The above three expressions return constants inf and nan of type number. The problem when simplifying this is that the resulting string will become:
print(inf) -- nil
print(-inf) -- attempt to perform arithmetic on global 'inf' (a nil value)
print(nan) -- nil
Expected behavior
The DivExpression should not simplify the expression when the right hand side is 0.
To Reproduce
Steps to reproduce the behavior:
Create a file divexpression.lua containing print(-1/0)
Describe the bug The DivExpression in ast.lua has a
simplify
argument which will perform the division and store the result if both left and right-hand side of the expression is a constant. This works great in all cases except when dividing by 0.The above three expressions return constants inf and nan of type number. The problem when simplifying this is that the resulting string will become:
Expected behavior The DivExpression should not simplify the expression when the right hand side is 0.
To Reproduce Steps to reproduce the behavior:
divexpression.lua
containingprint(-1/0)
lua cli.lua --preset Weak divexpression.lua
Observe
divexpression.obfuscated.lua