diff options
Diffstat (limited to 'lib/compiler/test')
| -rw-r--r-- | lib/compiler/test/bs_match_SUITE.erl | 24 | ||||
| -rw-r--r-- | lib/compiler/test/core_fold_SUITE.erl | 16 | ||||
| -rw-r--r-- | lib/compiler/test/fun_SUITE.erl | 19 | ||||
| -rw-r--r-- | lib/compiler/test/guard_SUITE.erl | 18 | ||||
| -rw-r--r-- | lib/compiler/test/match_SUITE.erl | 23 | ||||
| -rw-r--r-- | lib/compiler/test/warnings_SUITE.erl | 14 | 
6 files changed, 106 insertions, 8 deletions
| diff --git a/lib/compiler/test/bs_match_SUITE.erl b/lib/compiler/test/bs_match_SUITE.erl index 149b9bbb8f..10e3451e8f 100644 --- a/lib/compiler/test/bs_match_SUITE.erl +++ b/lib/compiler/test/bs_match_SUITE.erl @@ -34,7 +34,7 @@  	 otp_7188/1,otp_7233/1,otp_7240/1,otp_7498/1,  	 match_string/1,zero_width/1,bad_size/1,haystack/1,  	 cover_beam_bool/1,matched_out_size/1,follow_fail_branch/1, -	 no_partition/1,calling_a_binary/1]). +	 no_partition/1,calling_a_binary/1,binary_in_map/1]).  -export([coverage_id/1,coverage_external_ignore/2]). @@ -59,7 +59,7 @@ groups() ->         matching_and_andalso,otp_7188,otp_7233,otp_7240,         otp_7498,match_string,zero_width,bad_size,haystack,         cover_beam_bool,matched_out_size,follow_fail_branch, -       no_partition,calling_a_binary]}]. +       no_partition,calling_a_binary,binary_in_map]}].  init_per_suite(Config) -> @@ -1189,6 +1189,26 @@ call_binary(<<>>, Acc) ->  call_binary(<<H,T/bits>>, Acc) ->      T(<<Acc/binary,H>>). +binary_in_map(Config) when is_list(Config) -> +    ok = match_binary_in_map(#{key => <<42:8>>}), +    {'EXIT',{{badmatch,#{key := 1}},_}} = +	(catch match_binary_in_map(#{key => 1})), +    {'EXIT',{{badmatch,#{key := <<1023:16>>}},_}} = +	(catch match_binary_in_map(#{key => <<1023:16>>})), +    {'EXIT',{{badmatch,#{key := <<1:8>>}},_}} = +	(catch match_binary_in_map(#{key => <<1:8>>})), +    {'EXIT',{{badmatch,not_a_map},_}} = +	(catch match_binary_in_map(not_a_map)), +    ok. + +match_binary_in_map(Map) -> +    case 8 of +	N -> +	    #{key := <<42:N>>} = Map, +	    ok +    end. + +  check(F, R) ->      R = F(). diff --git a/lib/compiler/test/core_fold_SUITE.erl b/lib/compiler/test/core_fold_SUITE.erl index 6a7036d728..2de17e7653 100644 --- a/lib/compiler/test/core_fold_SUITE.erl +++ b/lib/compiler/test/core_fold_SUITE.erl @@ -60,6 +60,12 @@ t_element(Config) when is_list(Config) ->      X = make_ref(),      ?line X = id(element(1, {X,y,z})),      ?line b = id(element(2, {a,b,c,d})), +    (fun() -> +	    case {a,#{k=>X}} of +		{a,#{k:=X}}=Tuple -> +		    #{k:=X} = id(element(2, Tuple)) +	    end +    end)(),      %% No optimization, but should work.      Tuple = id({x,y,z}), @@ -204,6 +210,16 @@ eq(Config) when is_list(Config) ->      ?line ?CMP_DIFF(a, [a]),      ?line ?CMP_DIFF(a, {1,2,3}), +    ?CMP_SAME(#{a=>1.0,b=>2}, #{b=>2.0,a=>1}), +    ?CMP_SAME(#{a=>[1.0],b=>[2]}, #{b=>[2.0],a=>[1]}), + +    %% The rule for comparing keys are different in 17.x and 18.x. +    %% Just test that the results are consistent. +    Bool = id(#{1=>a}) == id(#{1.0=>a}),	%Unoptimizable. +    Bool = id(#{1=>a}) == #{1.0=>a},		%Optimizable. +    Bool = #{1=>a} == #{1.0=>a},		%Optimizable. +    io:format("Bool = ~p\n", [Bool]), +      ok.  %% OTP-7117. diff --git a/lib/compiler/test/fun_SUITE.erl b/lib/compiler/test/fun_SUITE.erl index 25b7f677b5..a3e9b7fe4e 100644 --- a/lib/compiler/test/fun_SUITE.erl +++ b/lib/compiler/test/fun_SUITE.erl @@ -21,10 +21,10 @@  -export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1,   	 init_per_group/2,end_per_group/2,  	 test1/1,overwritten_fun/1,otp_7202/1,bif_fun/1, -	 external/1,eep37/1,badarity/1]). +         external/1,eep37/1,eep37_dup/1,badarity/1]). -%% Internal export. --export([call_me/1]). +%% Internal exports. +-export([call_me/1,dup1/0,dup2/0]).  -include_lib("test_server/include/test_server.hrl"). @@ -32,7 +32,7 @@ suite() -> [{ct_hooks,[ts_install_cth]}].  all() ->       test_lib:recompile(?MODULE), -    [test1,overwritten_fun,otp_7202,bif_fun,external,eep37,badarity]. +    [test1,overwritten_fun,otp_7202,bif_fun,external,eep37,eep37_dup,badarity].  groups() ->       []. @@ -206,6 +206,17 @@ eep37(Config) when is_list(Config) ->      50 = UnusedName(8),      ok. +eep37_dup(Config) when is_list(Config) -> +    dup1 = (dup1())(), +    dup2 = (dup2())(), +    ok. + +dup1() -> +    fun _F() -> dup1 end. + +dup2() -> +    fun _F() -> dup2 end. +  badarity(Config) when is_list(Config) ->      {'EXIT',{{badarity,{_,[]}},_}} = (catch (fun badarity/1)()),      ok. diff --git a/lib/compiler/test/guard_SUITE.erl b/lib/compiler/test/guard_SUITE.erl index eb205d09a7..34bfdeb1e5 100644 --- a/lib/compiler/test/guard_SUITE.erl +++ b/lib/compiler/test/guard_SUITE.erl @@ -1556,6 +1556,24 @@ bad_constants(Config) when is_list(Config) ->  bad_guards(Config) when is_list(Config) ->      if erlang:float(self()); true -> ok end, + +    fc(catch bad_guards_1(1, [])), +    fc(catch bad_guards_1(1, [2])), +    fc(catch bad_guards_1(atom, [2])), + +    fc(catch bad_guards_2(#{a=>0,b=>0}, [])), +    fc(catch bad_guards_2(#{a=>0,b=>0}, [x])), +    fc(catch bad_guards_2(not_a_map, [x])), +    fc(catch bad_guards_2(42, [x])), +    ok. + +%% beam_bool used to produce GC BIF instructions whose +%% Live operands included uninitialized registers. + +bad_guards_1(X, [_]) when {{X}}, -X -> +    ok. + +bad_guards_2(M, [_]) when M#{a := 0, b => 0}, map_size(M) ->      ok.  %% Call this function to turn off constant propagation. diff --git a/lib/compiler/test/match_SUITE.erl b/lib/compiler/test/match_SUITE.erl index ae7d764535..1e778dca24 100644 --- a/lib/compiler/test/match_SUITE.erl +++ b/lib/compiler/test/match_SUITE.erl @@ -22,7 +22,7 @@  	 init_per_group/2,end_per_group/2,  	 pmatch/1,mixed/1,aliases/1,match_in_call/1,  	 untuplify/1,shortcut_boolean/1,letify_guard/1, -	 selectify/1,underscore/1,coverage/1]). +	 selectify/1,underscore/1,match_map/1,coverage/1]).  -include_lib("test_server/include/test_server.hrl"). @@ -35,7 +35,8 @@ all() ->  groups() ->       [{p,test_lib:parallel(),        [pmatch,mixed,aliases,match_in_call,untuplify, -       shortcut_boolean,letify_guard,selectify,underscore,coverage]}]. +       shortcut_boolean,letify_guard,selectify, +       underscore,match_map,coverage]}].  init_per_suite(Config) -> @@ -400,6 +401,24 @@ underscore(Config) when is_list(Config) ->      _ = is_list(Config),      ok. +-record(s, {map,t}). + +match_map(Config) when is_list(Config) -> +    Map = #{key=>{x,y},ignore=>anything}, +    #s{map=Map,t={x,y}} = do_match_map(#s{map=Map}), +    {a,#{k:={a,b,c}}} = do_match_map_2(#{k=>{a,b,c}}), +    ok. + +do_match_map(#s{map=#{key:=Val}}=S) -> +    %% Would crash with a 'badarg' exception. +    S#s{t=Val}. + +do_match_map_2(Map) -> +    case {a,Map} of +	{a,#{k:=_}}=Tuple -> +	    Tuple +    end. +  coverage(Config) when is_list(Config) ->      %% Cover beam_dead.      ok = coverage_1(x, a), diff --git a/lib/compiler/test/warnings_SUITE.erl b/lib/compiler/test/warnings_SUITE.erl index ad4ad91f74..0637041873 100644 --- a/lib/compiler/test/warnings_SUITE.erl +++ b/lib/compiler/test/warnings_SUITE.erl @@ -662,6 +662,20 @@ latin1_fallback(Conf) when is_list(Conf) ->  	    {warnings,[{1,compile,reparsing_invalid_unicode}]}  	   }],      [] = run(Conf, Ts2), + +    Ts3 = [{latin1_fallback3, +	    %% Test that the compiler fall backs to latin-1 with +	    %% a warning if a file has no encoding and does not +	    %% contain correct UTF-8 sequences. +	    <<"-ifdef(NOTDEFINED). +              t(_) -> \"",246,"\"; +              t(x) -> ok. +              -endif. +              ">>, +	    [], +	    {warnings,[{2,compile,reparsing_invalid_unicode}]}}], +    [] = run(Conf, Ts3), +      ok.  %%% | 
