Using literal 1.0 in JuMP @constraint throws an error

The following code throws an error:

using JuMP

m = Model()
@variable(m, x)
y = Vector{Any}(undef, 2)
y[1] = @variable(m, base_name=“y1”)
y[2] = 1.0

@constraint(m, sum([x * yi for yi in y]) == 1.0)

ERROR: MethodError: no method matching zero(::Type{AbstractJuMPScalar})
Closest candidates are:
zero(::Union{Type{P}, P}) where P<:Dates.Period at C:\Users\garys.julia\juliaup\julia-1.8.5+0.x64.w64.mingw32\share\julia\stdlib\v1.8\Dates\src\periods.jl:53
zero(::T) where T<:Dates.TimeType at C:\Users\garys.julia\juliaup\julia-1.8.5+0.x64.w64.mingw32\share\julia\stdlib\v1.8\Dates\src\types.jl:450
zero(::LinearAlgebra.Diagonal{T, StaticArraysCore.SVector{N, T}}) where {N, T} at C:\Users\garys.julia\packages\StaticArrays\VLqRb\src\SDiagonal.jl:41
…

Replacing y[2] = 1.0 with y[2] = one(AffExpr) produces no errors, as does rewriting the constraint as

@constraint(m, sum(+, [x * yi for yi in y]) == 1.0)

Is this a bug?

The real fix is that sum does not need to take an array:

@constraint(m, sum(x * yi for yi in y) == 1.0)

Your error stems from this:

julia> z = [x * yi for yi in y]
2-element Vector{AbstractJuMPScalar}:
 x*y1
 x

julia> sum(z)
ERROR: MethodError: no method matching zero(::Type{AbstractJuMPScalar})
Closest candidates are:
  zero(::Union{Type{P}, P}) where P<:Dates.Period at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/Dates/src/periods.jl:53
  zero(::GenericQuadExpr) at /Users/oscar/.julia/packages/JuMP/AKvOr/src/quad_expr.jl:113
  zero(::GenericAffExpr) at /Users/oscar/.julia/packages/JuMP/AKvOr/src/aff_expr.jl:200
  ...
Stacktrace:

In this case, your vector has an abstract element type, and we can’t figure out how to initialize the summation of an abstract type.

Thank you.