aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib
diff options
context:
space:
mode:
authorHans Bolinder <[email protected]>2016-04-22 08:53:26 +0200
committerHans Bolinder <[email protected]>2016-04-22 08:53:26 +0200
commit9bff4dbbaf44ff563b3d67c65061f5f0a7d7f944 (patch)
tree9d9317288e3ee8e573faee0d06c3bb67c17545b0 /lib/stdlib
parentf2cef11a16d8d5f643cdf913b46042db71bff867 (diff)
parent96c6513bb374c95a686027ed33c75704f94c244a (diff)
downloadotp-9bff4dbbaf44ff563b3d67c65061f5f0a7d7f944.tar.gz
otp-9bff4dbbaf44ff563b3d67c65061f5f0a7d7f944.tar.bz2
otp-9bff4dbbaf44ff563b3d67c65061f5f0a7d7f944.zip
Merge branch 'richcarl/assert-shut-up-dialyzer/PR-1002'
* richcarl/assert-shut-up-dialyzer/PR-1002: eunit: Remove -dialyzer attributes Avoid dialyzer warnings for unreachable code in asserts Make assert macro implementations uniform
Diffstat (limited to 'lib/stdlib')
-rw-r--r--lib/stdlib/include/assert.hrl29
1 files changed, 18 insertions, 11 deletions
diff --git a/lib/stdlib/include/assert.hrl b/lib/stdlib/include/assert.hrl
index 151794d114..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)())
@@ -149,7 +154,8 @@
-else.
-define(assertEqual(Expect, Expr),
begin
- ((fun (__X) ->
+ ((fun () ->
+ __X = (Expect),
case (Expr) of
__X -> ok;
__V -> erlang:error({assertEqual,
@@ -159,7 +165,7 @@
{expected, __X},
{value, __V}]})
end
- end)(Expect))
+ end)())
end).
-endif.
@@ -169,7 +175,8 @@
-else.
-define(assertNotEqual(Unexpected, Expr),
begin
- ((fun (__X) ->
+ ((fun () ->
+ __X = (Unexpected),
case (Expr) of
__X -> erlang:error({assertNotEqual,
[{module, ?MODULE},
@@ -178,7 +185,7 @@
{value, __X}]});
_ -> ok
end
- end)(Unexpected))
+ end)())
end).
-endif.