Skip to content

Confusing line number on variable both declared local and global #58468

@anqur

Description

@anqur

I was experimenting with local/global scoping in a non-interactive context, and stumbled upon this snippet:

for i = 1:10
    if false
        local a
    end
    global a
end

The line number from the error output is kinda confusing, which is 1. It's expected to be 3 (on local a) or 5 (on global a) I believe. Any ideas?

ERROR: LoadError: syntax: variable "a" declared both local and global
Stacktrace:
 [1] top-level scope
   @ D:\notes\hello.jl:1
in expression starting at D:\notes\hello.jl:1

My versioninfo:

julia> versioninfo()
Julia Version 1.11.5
Commit 760b2e5b73 (2025-04-14 06:53 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 12 × 11th Gen Intel(R) Core(TM) i5-11500H @ 2.90GHz
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, tigerlake)
Threads: 1 default, 0 interactive, 1 GC (on 12 virtual cores)

Metadata

Metadata

Assignees

No one assigned

    Labels

    parserLanguage parsing and surface syntax

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions