Skip to content

Mutable let block variable treated as immutable in Julia 1.10 #52531

Description

MWE:

let
    global set_a, get_a
    _a::Int       = -1
    set_a(a::Int) = (_a = a; return get_a())
    get_a()       = _a
end
    
set_a(1)
get_a()
set_a(2)
get_a()

Wrong output in Julia 1.10:

julia> let
           global set_a, get_a
           _a::Int       = -1
           set_a(a::Int) = (_a = a; return get_a())
           get_a()       = _a
       end
get_a (generic function with 1 method)

julia> set_a(1)
-1

julia> get_a()
-1

julia> set_a(2)
-1

julia> get_a()
-1

Correct output in Julia 1.9.4:

julia> let
           global set_a, get_a
           _a::Int       = -1
           set_a(a::Int) = (_a = a; return get_a())
           get_a()       = _a
       end
get_a (generic function with 1 method)

julia> set_a(1)
1

julia> get_a()
1

julia> set_a(2)
2

julia> get_a()
2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Labels

compiler:effectseffect analysiscompiler:loweringSyntax lowering (compiler front end, 2nd stage)priorityThis should be addressed urgently

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions