Closed lukaszsamson closed 2 months ago
It seems to be an intended feature at least using match?
, and the diffs for it are even nicely supported:
This seems like a valuable feature, perhaps we should try to find a way to make it officially documented and available?
Semantically-wise, I wonder if we couldn't make assert
support <-
which would be nicer than wrapping in match?
:
assert [a] when is_integer(a) <- my_list
match?
macro is a different case. It is documented to allow guards. It doesn't change semantics as it expands to case
clauses.
assert [a] when is_integer(a) <- my_list
Interesting idea but it brings inconsistency. In other instances <-
operator is followed by do
block
I agree with @lukaszsamson. If you want to use guards, you can use assert match?
. We should not allow when
inside =
in assert
, it is probably a side-effect of the implementation.
Elixir and Erlang/OTP versions
Erlang/OTP 26 [erts-14.2.5.2] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [jit]
Elixir 1.17.2 (compiled with Erlang/OTP 26)
Operating system
any
Current behavior
The following test unexpectedly passes.
Support for guards is not mentioned in https://hexdocs.pm/ex_unit/1.17.2/ExUnit.Assertions.html#assert/1
Expected behavior
Basing on the documentation I expect assert to not change language semantics. This code should emit a compilation error as guards are not allowed in match context. The same code without
assert
errors with