Skip to content

Commit

Permalink
Add error in signature
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Aug 14, 2018
1 parent fda8233 commit 4cb7d0a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/JuMP.jl
Expand Up @@ -83,7 +83,7 @@ struct OptimizerFactory
# * `Function`: a function, or
# * `DataType`: a type, or
# * `UnionAll`: a type with missing parameters.
constructor::Union{Function, DataType, UnionAll}
constructor
args::Tuple
kwargs # type changes from Julia v0.6 to v0.7 so we leave it untyped for now
end
Expand All @@ -102,8 +102,13 @@ the constructor call `IpoptOptimizer(print_level=0)`:
with_optimizer(IpoptOptimizer, print_level=0)
```
"""
function with_optimizer(constructor::Union{Function, DataType, UnionAll},
function with_optimizer(constructor,
args...; kwargs...)
if !applicable(constructor, args...)
error("$constructor is does not have any method with arguments $args.",
"The first argument of `with_optimizer` should be callable with",
" the other argument of `with_optimizer`.")
end
return OptimizerFactory(constructor, args, kwargs)
end

Expand Down
1 change: 1 addition & 0 deletions test/model.jl
Expand Up @@ -57,6 +57,7 @@ end
@test optimizer isa Optimizer
@test optimizer.a == 1
@test optimizer.b == 2
@test_throws ErrorException factory = with_optimizer(f, 1, 2)
factory = with_optimizer(f, 1, b = 2)
@test factory.constructor == f
@test factory.args == (1,)
Expand Down

0 comments on commit 4cb7d0a

Please sign in to comment.