Skip to content

Bypassed definition prevents an undefined error #57315

@TianChengJiang9911

Description

@TianChengJiang9911

Code:

global flag=false
function fun()
    global flag
    print(1)
    if flag
        flag_2=true
    else
        print(2)
        if flag_2
            print(3)
        end
        print(4)
    end
    print(5)
    return true
end
fun()

and I got

125true

Expected (as I replace the global flag with false):

global flag=false
function fun()
    global flag
    print(1)
    if false
        flag_2=true
    else
        print(2)
        if flag_2
            print(3)
        end
        print(4)
    end
    print(5)
    return true
end
fun()

and got

12ERROR: UndefVarError: flag_2 not defined
Stacktrace:
[1] fun()
@ Main .\REPL[2]:8
[2] top-level scope
@ REPL[3]:1

When definition of flag_2 is bypassed by the global flag, the code failed to raise an error and shouldn't continue running (as the number 5 printed)

Metadata

Metadata

Assignees

No one assigned

    Labels

    correctness bug ⚠Bugs that are likely to lead to incorrect results in user code without throwingfixed on masterregressionRegression in behavior compared to a previous version

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions