Strange error

Could someone explain to me what is happening here? Try running mwe1() and then mwe2()

function mwe1()
        initfloat::Vector{Float64} = zeros(1)
        Φ::Vector{Float64} = initfloat
        Θ̇::Vector{Float64} = initfloat
        for i = 1:1
            Θ̇[i] = 2.0
            println("Theta dot = ", Θ̇[i])
            Φ[i] = 0.1i  #Float x Int
            println("Theta dot = ", Θ̇[i])
        end
    end
    
function mwe2()
    i = 1
    Θ̇ = 2.0
    println("Theta dot = ", Θ̇)
    Φ = 0.1i  #Float x Int
    println("Theta dot = ", Θ̇)
end

Many thanks!

BTW:

julia> versioninfo()
Julia Version 1.7.2
Commit bf53498635 (2022-02-06 15:21 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 6
  JULIA_EDITOR = code
  JULIA_PROJECT = /home/rpowell/APCSv0.1.2/apcs.jl/

In mwe1, Φ and Θ̇ reference to the same array initfloat.

function mwe1()
    initfloat::Vector{Float64} = zeros(1)
    Φ::Vector{Float64} = initfloat  # it is not a copy, it is a new reference
    Θ̇::Vector{Float64} = initfloat  # it is too

    @show Φ === Θ̇  # true
    ...
end
3 Likes

Many thanks! I completely forgot about how that works. Silly me!