Skip to content

unreachable code interacts with scoping rules and changes program behavior #56874

@sadish-d

Description

@sadish-d

The code below prints:

I'm not guilty.

If you uncomment the line marked unleash me, it prints:

I'm guilty. But you're never going to know. Unless you've messed with time travel.

let
    let
        admit_guilt = true
    end
    if @isdefined(admit_guilt)
        admit_guilt && println("I'm guilty. But you're never going to know. Unless you've messed with time travel.")
    else
        println("I'm not guilty.")
        if false # code inside this block never executes
            println("a secret never spilled")
            # admit_guilt = true #---------------- unleash me
        end
    end
end

It reminds me of this #5148 (comment) , but I think there, the inner functions are getting pulled out and getting defined in the global scope (maybe?). I'm not sure what's going on here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions