diff options
author | Björn Gustavsson <[email protected]> | 2018-08-06 14:15:30 +0200 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2018-08-06 15:01:38 +0200 |
commit | 8944398e939ce1b8929150118a275d7fb852ac43 (patch) | |
tree | 0819e7ed2aeba754da5dfd057dd6a367ba30f622 /lib/compiler/test | |
parent | ce0ab49ca59dc56cb4774abc1f635b7ff9cf97df (diff) | |
download | otp-8944398e939ce1b8929150118a275d7fb852ac43.tar.gz otp-8944398e939ce1b8929150118a275d7fb852ac43.tar.bz2 otp-8944398e939ce1b8929150118a275d7fb852ac43.zip |
beam_validator: Fix false diagnostic for a receive nested in a try
When nesting a receive in a try/catch, there could be a false
diagnostic that a fragile term is used.
https://bugs.erlang.org/browse/ERL-684
Diffstat (limited to 'lib/compiler/test')
-rw-r--r-- | lib/compiler/test/receive_SUITE.erl | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/lib/compiler/test/receive_SUITE.erl b/lib/compiler/test/receive_SUITE.erl index 81ef0d33f2..37e737084a 100644 --- a/lib/compiler/test/receive_SUITE.erl +++ b/lib/compiler/test/receive_SUITE.erl @@ -25,7 +25,7 @@ init_per_group/2,end_per_group/2, init_per_testcase/2,end_per_testcase/2, export/1,recv/1,coverage/1,otp_7980/1,ref_opt/1, - wait/1]). + wait/1,recv_in_try/1]). -include_lib("common_test/include/ct.hrl"). @@ -44,7 +44,8 @@ all() -> groups() -> [{p,test_lib:parallel(), - [recv,coverage,otp_7980,ref_opt,export,wait]}]. + [recv,coverage,otp_7980,ref_opt,export,wait, + recv_in_try]}]. init_per_suite(Config) -> @@ -305,4 +306,48 @@ wait_1(r, _, _) -> wait_1(A, B, C) -> {A,B,C}. +recv_in_try(_Config) -> + self() ! {ok,fh}, {ok,fh} = recv_in_try(infinity, native), + self() ! {ok,ignored}, {ok,42} = recv_in_try(infinity, plain), + self() ! {error,ignored}, nok = recv_in_try(infinity, plain), + timeout = recv_in_try(1, plain), + ok. + +recv_in_try(Timeout, Format) -> + try + receive + {Status,History} -> + %% {test,is_tuple,{f,148},[{x,0}]}. + %% {test,test_arity,{f,148},[{x,0},2]}. + %% {get_tuple_element,{x,0},0,{y,1}}. %y1 is fragile. + %% + %% %% Here the fragility of y1 would be be progated to + %% %% the 'catch' below. Incorrect, since get_tuple_element + %% %% can't fail. + %% {get_tuple_element,{x,0},1,{x,2}}. + %% + %% remove_message. %y1 fragility cleared. + FH = case Format of + native -> + id(History); + plain -> + id(42) + end, + case Status of + ok -> + {ok,FH}; + error -> + nok + end + after Timeout -> + timeout + end + catch + %% The fragility of y1 incorrectly propagated to here. + %% beam_validator would complain. + throw:{error,Reason} -> + {nok,Reason} + end. + + id(I) -> I. |