Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Sep 17, 2023
1 parent a2bf99e commit ea1827b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
15 changes: 11 additions & 4 deletions src/nlp_expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1147,9 +1147,16 @@ end

function add_to_expression!(f::GenericNonlinearExpr, args...)
return error(
"`add_to_expression!` is not supported for expressions of type " *
"`$(typeof(f))` because they cannot be modified in-place. " *
"Instead of `add_to_expression!(expr, args..)`, use " *
"`expr += *(args...)`.",
"""
`add_to_expression!` is not supported for expressions of type
`$(typeof(f))` because they cannot be modified in-place.
Instead of `add_to_expression!(expr, args..)`, use one of the following:
```julia
expr += *(args...)
# or
import MutableArithmetics as MA
expr = MA.operate!!(MA.add_mul, expr, args...)
```
""",
)
end
15 changes: 11 additions & 4 deletions test/test_nlp_expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -932,10 +932,17 @@ function test_add_to_expression!()
y = zero(NonlinearExpr)
@test_throws(
ErrorException(
"`add_to_expression!` is not supported for expressions of type " *
"`$(typeof(y))` because they cannot be modified in-place. " *
"Instead of `add_to_expression!(expr, args..)`, use " *
"`expr += *(args...)`.",
"""
`add_to_expression!` is not supported for expressions of type
`$(typeof(f))` because they cannot be modified in-place.
Instead of `add_to_expression!(expr, args..)`, use one of the following:
```julia
expr += *(args...)
# or
import MutableArithmetics as MA
expr = MA.operate!!(MA.add_mul, expr, args...)
```
""",
),
add_to_expression!(y, 2.0, sin(x)),
)
Expand Down

0 comments on commit ea1827b

Please sign in to comment.