diff options
author | Richard Carlsson <[email protected]> | 2016-03-30 16:29:58 +0200 |
---|---|---|
committer | Hans Bolinder <[email protected]> | 2016-04-21 12:38:46 +0200 |
commit | e0e021b80033ddf04f805dbb451b0df2ec291cbd (patch) | |
tree | 1a7ffbf90dd9824a7a0f68b5efe292d8ff487924 /lib | |
parent | 398b7cb10fdf21c98514697d70f01e8ca7f1aad7 (diff) | |
download | otp-e0e021b80033ddf04f805dbb451b0df2ec291cbd.tar.gz otp-e0e021b80033ddf04f805dbb451b0df2ec291cbd.tar.bz2 otp-e0e021b80033ddf04f805dbb451b0df2ec291cbd.zip |
Avoid dialyzer warnings for unreachable code in asserts
Dialyzer would warn about uses of the ?assert(BoolExpr) macro in assert.hrl
if the argument was known to be boolean-only.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/stdlib/include/assert.hrl | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/stdlib/include/assert.hrl b/lib/stdlib/include/assert.hrl index 74fdbf57aa..9e5d4eb598 100644 --- a/lib/stdlib/include/assert.hrl +++ b/lib/stdlib/include/assert.hrl @@ -59,19 +59,22 @@ -define(assert(BoolExpr),ok). -else. %% The assert macro is written the way it is so as not to cause warnings -%% for clauses that cannot match, even if the expression is a constant. +%% for clauses that cannot match, even if the expression is a constant or +%% is known to be boolean-only. -define(assert(BoolExpr), begin ((fun () -> + __T = is_process_alive(self()), % cheap source of truth case (BoolExpr) of - true -> ok; + __T -> ok; __V -> erlang:error({assert, [{module, ?MODULE}, {line, ?LINE}, {expression, (??BoolExpr)}, {expected, true}, - case __V of false -> {value, __V}; - _ -> {not_boolean,__V} + case not __T of + __V -> {value, false}; + _ -> {not_boolean, __V} end]}) end end)()) @@ -85,15 +88,17 @@ -define(assertNot(BoolExpr), begin ((fun () -> + __F = not is_process_alive(self()), case (BoolExpr) of - false -> ok; + __F -> ok; __V -> erlang:error({assert, [{module, ?MODULE}, {line, ?LINE}, {expression, (??BoolExpr)}, {expected, false}, - case __V of true -> {value, __V}; - _ -> {not_boolean,__V} + case not __F of + __V -> {value, true}; + _ -> {not_boolean, __V} end]}) end end)()) |