Feature request and Brainstorming , global let (issue #37187)

The warning prints either way, the error is only thrown when the code actually runs:

Projects $ cat test.jl
i = 0
if rand() < 0.5
  for x in 1:10
    i += x
  end
end
println(i)


Projects $ julia test.jl
┌ Warning: Assignment to `i` in soft scope is ambiguous because a global variable by the same name exists: `i` will be treated as a new local. Disambiguate by using `local i` to suppress this warning or `global i` to assign to the existing global variable.
└ @ /d/Documents/Projects/test.jl:4
0


Projects $ julia test.jl
┌ Warning: Assignment to `i` in soft scope is ambiguous because a global variable by the same name exists: `i` will be treated as a new local. Disambiguate by using `local i` to suppress this warning or `global i` to assign to the existing global variable.
└ @ /d/Documents/Projects/test.jl:4
ERROR: LoadError: UndefVarError: i not defined
Stacktrace:
 [1] top-level scope at /d/Documents/Projects/test.jl:4
 [2] include(::Function, ::Module, ::String) at ./Base.jl:380
 [3] include(::Module, ::String) at ./Base.jl:368
 [4] exec_options(::Base.JLOptions) at ./client.jl:296
 [5] _start() at ./client.jl:506
in expression starting at /d/Documents/Projects/test.jl:2
1 Like