Skip to content

Commit

Permalink
Add comments for the assert
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Apr 21, 2018
1 parent b6c296f commit 3303478
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ end
constructconstraint!(_error::Function, q::QuadExpr, lb, ub) = _error("Two-sided quadratic constraints not supported. (Try @NLconstraint instead.)")

function constructconstraint!(_error::Function, expr, lb, ub)
# It could happen that a call is dispatched to this method with `lb` and `ub` that are `Number`,

This comment has been minimized.

Copy link
@mlubin

mlubin Apr 21, 2018

Member

What about an _error call at the end that explains this? @assert is not always guaranteed to run on 0.7+:

"The assert function (and @assert macro) have been documented that they are not guaranteed to run under various optimization levels and should therefore not be used to e.g. verify passwords."
https://github.com/JuliaLang/julia/blob/1c5ed7082516c8a8c259907ceef908ba0c9d2107/NEWS.md

# e.g. if there is not `constructconstraint!` method defined for the type of `expr`.
# In that case, no error will be thrown and `@constraint` will silently do nothing.
# We want to avoid that so we use this assert.
@assert !(lb isa Number) || !(ub isa Number)
lb isa Number || _error(string("Expected $lb to be a number."))
ub isa Number || _error(string("Expected $ub to be a number."))
Expand Down

0 comments on commit 3303478

Please sign in to comment.