Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

[BUG] Local Variable Scope Should Include Loop Condition #4

Open
soh-cah-toa opened this Issue · 0 comments

2 participants

Kevin Polulak François Perrad
Kevin Polulak

There's an example in Programming Lua, 2nd Edition that looks like (with a few subtle modifications):

local x = 10000
local sqr = x / 2

repeat
    sqr = (sqr + x / sqr) / 2
    local err = math.abs(sqr^2 - x)

    print(x)

    x = x - 1
until err < x / 10000

The output should be:

10000
9999
9998
9997
9996
9995
9994
9993
9992

However, parrot-lua spits out a runtime error:

10000
lua.pbc: example.lua:9: attempt to compare nil with number
stack traceback:
        example.lua:9: in main chunk
        [PIR]: in function 'docall'
        [PIR]: in function 'handle_script'
        [PIR]: in function 'main'

In Lua, the scope of local variables declared inside a loop includes the condition as well. However, it seems that parrot-lua does not know about this common mistake.

Note that this behavior is new in Lua 5.1.

François Perrad fperrad was assigned
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.