aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib/src/erl_internal.erl
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2018-08-10 07:43:31 +0200
committerBjörn Gustavsson <[email protected]>2018-08-13 09:26:36 +0200
commit7e1eb2ed1f724945884d839bd8a99154e9382849 (patch)
tree42dd357548847ad0197c825157a2b091838a6099 /lib/stdlib/src/erl_internal.erl
parent77d307e6c3e705e14843101d4c5348c6c079ace0 (diff)
downloadotp-7e1eb2ed1f724945884d839bd8a99154e9382849.tar.gz
otp-7e1eb2ed1f724945884d839bd8a99154e9382849.tar.bz2
otp-7e1eb2ed1f724945884d839bd8a99154e9382849.zip
Correct error behavior of is_map_key/2 in guards
Consider the following functions: foo() -> bar(not_a_map). bar(M) when not is_map_key(a, M) -> ok; bar(_) -> error. What will `foo/0` return? It depends. If the module is compiled with the default compiler options, the return value will be `ok`. If the module is compiled with the `inline` option, the return value will be `error`. The correct value is `error`, because the call to `is_map_key/2` when the second argument is not a map should fail the entire guard. That is the way other failing guards BIFs are handled. For example: foo() -> bar(not_a_tuple). bar(T) when not element(1, T) -> ok; bar(_) -> error. `foo/0` always returns `error` (whether the code is inlined or not). This bug can be fixed by changing the classification of `is_map_key/2` in the `erl_internal` module. It is now classified as a type test, which is incorrect because type tests should not fail. Reclassifying it as a plain guard BIF corrects the bug. This correction also fixes the internal consistency check failure which was reported in: https://bugs.erlang.org/browse/ERL-699
Diffstat (limited to 'lib/stdlib/src/erl_internal.erl')
-rw-r--r--lib/stdlib/src/erl_internal.erl2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/stdlib/src/erl_internal.erl b/lib/stdlib/src/erl_internal.erl
index b311a843c2..939abaff00 100644
--- a/lib/stdlib/src/erl_internal.erl
+++ b/lib/stdlib/src/erl_internal.erl
@@ -74,6 +74,7 @@ guard_bif(element, 2) -> true;
guard_bif(float, 1) -> true;
guard_bif(floor, 1) -> true;
guard_bif(hd, 1) -> true;
+guard_bif(is_map_key, 2) -> true;
guard_bif(length, 1) -> true;
guard_bif(map_size, 1) -> true;
guard_bif(map_get, 2) -> true;
@@ -109,7 +110,6 @@ new_type_test(is_function, 2) -> true;
new_type_test(is_integer, 1) -> true;
new_type_test(is_list, 1) -> true;
new_type_test(is_map, 1) -> true;
-new_type_test(is_map_key, 2) -> true;
new_type_test(is_number, 1) -> true;
new_type_test(is_pid, 1) -> true;
new_type_test(is_port, 1) -> true;