lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Thu, May 30, 2019 at 10:16 PM Roberto Ierusalimschy wrote:
> 2)
> The bug with wrong S2N conversion has been reported for previous "work
> versions", but still not fixed:
> for i = "2", 3 do print(math.type(i)) end  --> float float
> According to the manual, the value must be integer.

The manual says this about a numerical for:

  The loop starts by evaluating once the three control expressions;
  they must all result in numbers.

So, I would say that |for i = "2", 3| is unspecified in the manual.


There is another part of the manual which describes how "they result in numbers":

> Several places in Lua coerce strings to numbers when necessary.
> A string is converted to an integer or a float following its syntax and the rules of the Lua lexer.

If a string argument is prohibited in numeric for-loop then an error should be raised.
Otherwise, the conversion should comply with usual rule for S2N conversion.