Skip to content

Commit 87fcc06

Browse files
authored
Merge pull request #982 from JuliaOpt/bl/fix980
Workaround for issue #980
2 parents 49b8f40 + c5cb844 commit 87fcc06

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

src/Utilities/functions.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,8 @@ end
833833
function operate_term(::typeof(*), α::T, t::MOI.ScalarAffineTerm{T}) where T
834834
MOI.ScalarAffineTerm* t.coefficient, t.variable_index)
835835
end
836-
function operate_term(::typeof(*), t::MOI.ScalarAffineTerm{T}, β::T) where T
836+
# `<:Number` is a workaround for https://github.com/JuliaOpt/MathOptInterface.jl/issues/980
837+
function operate_term(::typeof(*), t::MOI.ScalarAffineTerm{T}, β::T) where T<:Number
837838
MOI.ScalarAffineTerm(t.coefficient * β, t.variable_index)
838839
end
839840
function operate_term(::typeof(*), α::T, t::MOI.ScalarAffineTerm{T}, β::T) where T
@@ -1443,9 +1444,10 @@ function operate(::typeof(*), ::Type{T},
14431444
return operate(*, T, α, f)
14441445
end
14451446

1447+
# `<:Number` is a workaround for https://github.com/JuliaOpt/MathOptInterface.jl/issues/980
14461448
function operate!(::typeof(*), ::Type{T},
14471449
f::Union{MOI.ScalarAffineFunction{T},
1448-
MOI.ScalarQuadraticFunction{T}}, α::T) where T
1450+
MOI.ScalarQuadraticFunction{T}}, α::T) where T<:Number
14491451
map_terms!(term -> operate_term(*, term, α), f)
14501452
f.constant *= α
14511453
return f

test/issue980.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module Issue980
2+
3+
import MathOptInterface
4+
const MOI = MathOptInterface
5+
6+
abstract type StaticArray end
7+
(::Type{SA})(x...) where {SA <: StaticArray} = SA(x)
8+
9+
function crash()
10+
model = MOI.Utilities.Model{Float64}()
11+
bridged = MOI.Bridges.LazyBridgeOptimizer(MOI.Utilities.Model{Float64}())
12+
MOI.copy_to(bridged, model)
13+
end
14+
15+
crash()
16+
17+
end

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ const MOIB = MathOptInterface.Bridges
66

77
using Test
88

9+
# It needs to be called first to trigger the crash.
10+
include("issue980.jl")
11+
912
# Tests for solvers are located in MOI.Test.
1013

1114
include("dummy.jl")

0 commit comments

Comments
 (0)