Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jun 9, 2018. It is now read-only.
This repository was archived by the owner on Jun 9, 2018. It is now read-only.

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

@soh-cah-toa

Description

@soh-cah-toa

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions