Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error hint on Num in boolean context #2919

Closed
wants to merge 1 commit into from
Closed

Error hint on Num in boolean context #2919

wants to merge 1 commit into from

Conversation

baggepinnen
Copy link
Contributor

Use of a symbolic expression in a boolean context is a rather common user mistake, this PR adds a hint with possible fixes
image

Comment on lines +281 to +288
println(io, "\nA symbolic expression appeared in a Boolean context. This error arises in situations where Julia expects a Bool, like ")
printstyled(io, "if boolean_condition", color=:blue)
printstyled(io, "\t\t use ifelse(boolean_condition, then branch, else branch)\n", color=:green)
printstyled(io, "x && y", color=:blue)
printstyled(io, "\t\t\t\t use x & y\n", color=:green)
printstyled(io, "booelan_condition ? a : b", color=:blue)
printstyled(io, "\t use ifelse(boolean_condition, a, b)\n", color=:green)
print(io, "but a symbolic expression appeared instead of a Bool. For help regarding control flow with symbolic variables, see https://docs.sciml.ai/ModelingToolkit/dev/basics/FAQ/#How-do-I-handle-if-statements-in-my-symbolic-forms?")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
println(io, "\nA symbolic expression appeared in a Boolean context. This error arises in situations where Julia expects a Bool, like ")
printstyled(io, "if boolean_condition", color=:blue)
printstyled(io, "\t\t use ifelse(boolean_condition, then branch, else branch)\n", color=:green)
printstyled(io, "x && y", color=:blue)
printstyled(io, "\t\t\t\t use x & y\n", color=:green)
printstyled(io, "booelan_condition ? a : b", color=:blue)
printstyled(io, "\t use ifelse(boolean_condition, a, b)\n", color=:green)
print(io, "but a symbolic expression appeared instead of a Bool. For help regarding control flow with symbolic variables, see https://docs.sciml.ai/ModelingToolkit/dev/basics/FAQ/#How-do-I-handle-if-statements-in-my-symbolic-forms?")
println(io,
"\nA symbolic expression appeared in a Boolean context. This error arises in situations where Julia expects a Bool, like ")
printstyled(io, "if boolean_condition", color = :blue)
printstyled(
io, "\t\t use ifelse(boolean_condition, then branch, else branch)\n",
color = :green)
printstyled(io, "x && y", color = :blue)
printstyled(io, "\t\t\t\t use x & y\n", color = :green)
printstyled(io, "booelan_condition ? a : b", color = :blue)
printstyled(io, "\t use ifelse(boolean_condition, a, b)\n", color = :green)
print(io,
"but a symbolic expression appeared instead of a Bool. For help regarding control flow with symbolic variables, see https://docs.sciml.ai/ModelingToolkit/dev/basics/FAQ/#How-do-I-handle-if-statements-in-my-symbolic-forms?")

@ChrisRackauckas
Copy link
Member

This is the wrong repository. It's effectively piracy here. It should be in Symbolics.jl

@ChrisRackauckas ChrisRackauckas deleted the errorhint branch August 2, 2024 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants