A weird error when use two `in` in a for loop

MWE:

function blur7!(in::Array{T,2},bv::Array{T,2}) where T
    m,n = size(in)
    bh = Array{T,2}(undef,32,2)
    for tx in in 1:32:m   #here are two `in`s
        bh[i+1,1] = in[tx,1]
    end
end
m = 5
n = 5
A = collect(reshape(1.0:m*n,m,n))
B = Array{Float64}(undef,m-2,n-2)
blur7!(A,B)

Here I make a mistake, I mistype an additional in, however it doesn’t cause a syntax error, instead:

ERROR: ArgumentError: invalid index: 1.0 of
type Float64

It takes me some time to fix this type unstable problem, This is weird.Version info:

julia> versioninfo()
Julia Version 1.2.0-rc1.0
Commit 7097799cf1 (2019-05-30 02:22 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
Environment:

Any idea?

It’s being parsed as

for tx in in
    1:32:m
    bh[i+1,1] = in[tx,1]
end

where the second in is your function argument. Since it is an Array{Float64,2}, tx will contain floats.

2 Likes

thanks, maybe I should not use keyword for argument names…

2 Likes