"non-matching indices between left and right hand side:" in using @tensor in function

Hi,

I have the following code

using BenchmarkTools, TensorOperations, LoopVectorization


function level4(A, factor) 
    @tensor B[i,j,k,l] := factor[1]* A[i, j, k, l] +
    factor[2]* A[i, j, l, k] +
    factor[3]* A[j, i, k, l] +
    factor[4]* A[j, i, l, k]

    B
end

factor = [0.1, 0.2, 0.3, 0.4]
n = 30
A=rand(n,n,n,n)
@btime level4(A, factor)

I got the error message as

ERROR: LoadError: TensorOperations.IndexError{String}("non-matching indices between left and right hand side: \$(Expr(:(:=), :(var\"##293\"[i, j, k, l]), :(var\"##291\"[1] * var\"##292\"[i, j, k, l] + var\"##291\"[2] * var\"##292\"[i, j, l, k] + var\"##291\"[3] * var\"##292\"[j, i, k, l] + var\"##291\"[4] * var\"##292\"[j, i, l, k])))")
Stacktrace:
  [1] level4(A::Array{Float64, 4}, factor::Vector{Float64})
...

So what would be the reason and solution for the above problem? Thank you very much