aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/test/beam_validator_SUITE_data/receive_stacked.erl
blob: b95fa9ca62e06361382f076058397cb1a1493f06 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
-module(receive_stacked).
-compile([export_all,nowarn_export_all]).

%% Messages may be stored outside any process heap until they
%% have been accepted by the 'remove_message' instruction.
%% When matching of a message fails, it is not allowed to
%% leave references to the message or any part of it in
%% the Y registers. An experimental code generator could
%% do that, causing an emulator crash if there happenened to
%% be a garbage collection.
%%
%% The 'S' file corresponding to this file was compiled with
%% that experimental code generator.

f1() ->
    receive
        X when is_integer(X) ->
            id(42),
            X
    end.

f2() ->
    receive
        [X] ->
            Res = {ok,X},
            id(42),
            {Res,X}
    end.

f3() ->
    receive
        [H|_] when is_integer(H) ->
            Res = {ok,H},
            id(42),
            {Res,H}
    end.

f4() ->
    receive
        [_|T] when is_list(T) ->
            Res = {ok,T},
            id(42),
            {Res,T}
    end.

f5() ->
    receive
        {X} when is_integer(X) ->
            Res = #{key=>X},
            id(42),
            {Res,X}
    end.

f6() ->
    receive
        <<_:8,T/binary>> when byte_size(T) > 8 ->
            id(42),
            T
    end.

f7() ->
    receive
        <<_:8,T/binary>> when is_binary(T) ->
            id(42),
            T
    end.

f8() ->
    receive
        <<_:8,T/binary>> = Bin when is_binary(Bin) ->
            id(42),
            T
    end.

m1() ->
    receive
        #{key:=V} when is_integer(V) ->
            id(42),
            [V]
    end.

m2() ->
    K1 = id(key1),
    K2 = id(key2),
    receive
        #{K1:=V1,K2:=V2} when is_integer(V1), is_integer(V2) ->
            id(42),
            {V1,V2}
    end.

id(I) ->
    I.