diff options
author | John Högberg <[email protected]> | 2019-04-30 09:11:44 +0200 |
---|---|---|
committer | John Högberg <[email protected]> | 2019-04-30 09:11:44 +0200 |
commit | 759ec896d7f254db2996cbb503c1ef883e6714b0 (patch) | |
tree | 920165a88f18fa6e7833cd28535ccf21231b837b /lib/compiler/test/bs_match_SUITE.erl | |
parent | 62a01f1544ad542c880982129e411ea223464e09 (diff) | |
parent | 65189902618e01e64326404fae9b1e63ff87b536 (diff) | |
download | otp-759ec896d7f254db2996cbb503c1ef883e6714b0.tar.gz otp-759ec896d7f254db2996cbb503c1ef883e6714b0.tar.bz2 otp-759ec896d7f254db2996cbb503c1ef883e6714b0.zip |
Merge branch 'john/compiler/fix-missing-match-reposition/ERL-923'
* john/compiler/fix-missing-match-reposition/ERL-923:
compiler: Propagate match context position on fail path
Diffstat (limited to 'lib/compiler/test/bs_match_SUITE.erl')
-rw-r--r-- | lib/compiler/test/bs_match_SUITE.erl | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/lib/compiler/test/bs_match_SUITE.erl b/lib/compiler/test/bs_match_SUITE.erl index 41e4918b1e..d97f49c56e 100644 --- a/lib/compiler/test/bs_match_SUITE.erl +++ b/lib/compiler/test/bs_match_SUITE.erl @@ -1891,15 +1891,37 @@ expression_before_match_1(R) -> %% Make sure that context positions are updated on calls. restore_on_call(Config) when is_list(Config) -> - ok = restore_on_call_1(<<0, 1, 2>>). + ok = restore_on_call_plain(<<0, 1, 2>>), + <<"x">> = restore_on_call_match(<<0, "x">>), + ok. -restore_on_call_1(<<0, Rest/binary>>) -> - <<2>> = restore_on_call_2(Rest), - <<2>> = restore_on_call_2(Rest), %% {badmatch, <<>>} on missing restore. +restore_on_call_plain(<<0, Rest/binary>>) -> + <<2>> = restore_on_call_plain_1(Rest), + %% {badmatch, <<>>} on missing restore. + <<2>> = restore_on_call_plain_1(Rest), ok. -restore_on_call_2(<<1, Rest/binary>>) -> Rest; -restore_on_call_2(Other) -> Other. +restore_on_call_plain_1(<<1, Rest/binary>>) -> Rest; +restore_on_call_plain_1(Other) -> Other. + +%% Calls a function that moves the match context passed to it, and then matches +%% on its result to confuse the reposition algorithm's success/fail logic. +restore_on_call_match(<<0, Bin/binary>>) -> + case skip_until_zero(Bin) of + {skipped, Rest} -> + Rest; + not_found -> + %% The match context did not get repositioned before the + %% bs_get_tail instruction here. + Bin + end. + +skip_until_zero(<<0,Rest/binary>>) -> + {skipped, Rest}; +skip_until_zero(<<_C,Rest/binary>>) -> + skip_until_zero(Rest); +skip_until_zero(_) -> + not_found. %% 'catch' must invalidate positions. restore_after_catch(Config) when is_list(Config) -> @@ -1983,5 +2005,4 @@ do_matching_meets_apply(_Bin, {Handler, State}) -> %% Another case of the above. Handler:abs(State). - id(I) -> I. |