Wrong type when changing a number variable into a string (includes fix) #20
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
When running the following Lua code in LuaJ, the type of the variable
adoesn't change tostring, but remains anumber. This causes an unexpected behaviour when assigning strings that looks like numbers to a variable that was of typenumber. This doesn't happen when variables are first initialized tostringtype, likebin the example below.On other Lua interpreters, the code runs as expected. I think that problem arises in the class
NumberValueEntryinLuaTable.java, in particular in the method that is called when the entry needs to be changed:Here you can see that if the new value can be coerced to a number, the entry is updated just by changing its double value to the new value, converted to double. Only if the new value is not number-like, a new entry with the correct type is returned. I don't get why there's the need to have a
NumberValueEntryin the first place, but instead of removing it altogether, it could be fixed keeping the entry-reusing logic by checking the new value type instead of trying to coerce it to a number. The change below fixes the example above:I can make a pull request if you agree.
Yes it is a bug. Make a pull request.