elixir icon indicating copy to clipboard operation
elixir copied to clipboard

Compiler warning when using a variable bound in assert_receive

Open alco opened this issue 12 years ago • 4 comments

The following code causes the compiler to emit a warning:

assert_receive {:ok, num}  # line 10
assert ^num = 13           # line 11
test/exunit_export_test.exs:11: warning: variable num@1 exported from 'receive' (line 10)

Example repo with 2 tags: warning and no-warning – https://github.com/alco/ex_unit-warning-exported-var

alco avatar Oct 03 '14 09:10 alco

Interesting, I am running the latest code on master branch and didn't receive any warning when running mix test on your linked mix project.

SocialfiPanda avatar Oct 07 '14 05:10 SocialfiPanda

@jw2013 you need to check out the warning tag.

alco avatar Oct 07 '14 12:10 alco

@alco Ah, thanks so much for the clarification.

Is there any particular reason we don't use this instead:

num = 13                          # line 10
assert_receive {:ok, ^num}        # line 11

SocialfiPanda avatar Oct 11 '14 03:10 SocialfiPanda

It happens beyond assert_receive example with every macro + export_head before ^, e.g:

destructure([x], [3])
^x = 3

and comes from erl_lint.erl.

lexmag avatar Jan 16 '15 00:01 lexmag