Scoping rules in try blocks

Could anyone explain the scoping rules below (and if it is expected)? They seem rather unintuitive to me

julia> let
       try
           x = 2
       end
       y = x + 1
       end
ERROR: UndefVarError: x not defined

julia> let
       try
           x = 2
       end
       x = x + 1
       end
3

Not just try block.
Assignment without global makes the variable local in the scope so in the first case x is local to the try and in the second case the x is local to the let.
This is similar to Race condition caused by variable scope getting lifted from a multithreaded context · Issue #14948 · JuliaLang/julia · GitHub

1 Like

But isn’t this still unintuitive that you can change the scope of x by calling x=x? Seems like a hack with potentially little harm however, because one would not call x = f(x) when x is not defined in the current scope unless referring to the previous x as the input to f so it kind of works out anyways, but still weird.

The scope is defined by the outer most block that has an assignment

Interesting.