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

docs: assert_raise example is a compiler warning in Elixir 1.18 #14111

Closed
nathany-copia opened this issue Dec 23, 2024 · 5 comments
Closed

docs: assert_raise example is a compiler warning in Elixir 1.18 #14111

nathany-copia opened this issue Dec 23, 2024 · 5 comments

Comments

@nathany-copia
Copy link

nathany-copia commented Dec 23, 2024

Elixir and Erlang/OTP versions

Erlang/OTP 27 [erts-15.2] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1] [jit] [dtrace]

Elixir 1.18.0 (compiled with Erlang/OTP 27)

Operating system

macOS 15.2

Current behavior

The documentation for assert_raise suggests using 1 + "test" to get an Arithmetic Error.
https://hexdocs.pm/ex_unit/ExUnit.Assertions.html#assert_raise/2

assert_raise ArithmeticError, fn ->
  1 + "test"
end

Expected behavior

While an Arithmetic Error is still the case at runtime, Elixir 1.18 provides a compiler warning for code like this, so maybe it's no longer the best example?

The RuntimeError provided is a better example. Should the ArithmeticError example be removed?
https://github.com/elixir-lang/elixir/blob/main/lib/ex_unit/lib/ex_unit/assertions.ex#L788

@vanderhoop
Copy link
Contributor

I had a similar issue in a test that needed to deliberately raise. If an ArithmeticError is still desired, 9 / 0 did the trick without making the compiler barf.

@josevalim
Copy link
Member

@vanderhoop do you want to send a PR that uses a division by zero?

@vanderhoop
Copy link
Contributor

@josevalim I'm traveling for the holidays at the moment, but I'd be happy to open a quick PR on the 26th if it hasn't been done by then.

@josevalim
Copy link
Member

I went ahead as I am doing a new release soon!

josevalim added a commit that referenced this issue Dec 24, 2024
@nathany-copia
Copy link
Author

nathany-copia commented Dec 24, 2024

thank you @vanderhoop and @josevalim -- happy holidays! 🎄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants