diff options
author | Björn-Egil Dahlberg <[email protected]> | 2014-03-17 16:53:37 +0100 |
---|---|---|
committer | Björn-Egil Dahlberg <[email protected]> | 2014-03-17 17:47:37 +0100 |
commit | 5638ca15d05e9b05d64ade0e03492c13d020439b (patch) | |
tree | 0e06b2caf24f27dc80583fbf8cb3c42d80311d4c /lib | |
parent | d92b9dc2aa02871a43fb23ff61dc002b47a14270 (diff) | |
download | otp-5638ca15d05e9b05d64ade0e03492c13d020439b.tar.gz otp-5638ca15d05e9b05d64ade0e03492c13d020439b.tar.bz2 otp-5638ca15d05e9b05d64ade0e03492c13d020439b.zip |
compiler: Transform M#{} to is_map(M)
Core should not understand M#{}
Instead transform M#{} to
case _cor0 of
<_cor1>
when call 'erlang':'is_map'
(_cor0) ->
_cor1
( <_cor2> when 'true' ->
primop 'match_fail'
('badarg')
-| ['compiler_generated'] )
end
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compiler/src/v3_core.erl | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/compiler/src/v3_core.erl b/lib/compiler/src/v3_core.erl index bf3368c31d..082809b8a0 100644 --- a/lib/compiler/src/v3_core.erl +++ b/lib/compiler/src/v3_core.erl @@ -743,8 +743,25 @@ expr_map(M0,Es0,A,St0) -> {M1,Mps,St1} = safe(M0, St0), case is_valid_map_src(M1) of true -> - {Es1,Eps,St2} = map_pair_list(Es0, St1), - {ann_c_map(A,M1,Es1),Mps++Eps,St2}; + case {M1,Es0} of + {#c_var{}, []} -> + %% transform M#{} to is_map(M) + {Vpat,St2} = new_var(St1), + {Fpat,St3} = new_var(St2), + Cs = [#iclause{ + anno=A, + pats=[Vpat], + guard=[#icall{anno=#a{anno=A}, + module=#c_literal{anno=A,val=erlang}, + name=#c_literal{anno=A,val=is_map}, + args=[Vpat]}], + body=[Vpat]}], + Fc = fail_clause([Fpat], A, #c_literal{val=badarg}), + {#icase{anno=#a{anno=A},args=[M1],clauses=Cs,fc=Fc},Mps,St3}; + {_,_} -> + {Es1,Eps,St2} = map_pair_list(Es0, St1), + {ann_c_map(A,M1,Es1),Mps++Eps,St2} + end; false -> throw(bad_map) end. |