diff options
author | Björn-Egil Dahlberg <[email protected]> | 2014-08-18 18:32:54 +0200 |
---|---|---|
committer | Björn-Egil Dahlberg <[email protected]> | 2014-08-22 18:12:29 +0200 |
commit | ef6d25edd8e7975d20d5ac68ef89524743a245ea (patch) | |
tree | d81cc0a4194ef2474f6878abb931f968e1404ff6 /lib/compiler | |
parent | db2f7bc3392196509a3c5a9e19f78f8bf6b30e2c (diff) | |
download | otp-ef6d25edd8e7975d20d5ac68ef89524743a245ea.tar.gz otp-ef6d25edd8e7975d20d5ac68ef89524743a245ea.tar.bz2 otp-ef6d25edd8e7975d20d5ac68ef89524743a245ea.zip |
compiler: Normalize unary ops on Maps key literals
Unary ops are normalized before core transformation, i.e. handle
negative integers as map keys.
Strictly speaking, map keys are expressions but by handling them as
patterns we can normalize negative integers.
Diffstat (limited to 'lib/compiler')
-rw-r--r-- | lib/compiler/src/sys_pre_expand.erl | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/compiler/src/sys_pre_expand.erl b/lib/compiler/src/sys_pre_expand.erl index 761ae8409c..b1e0bf51aa 100644 --- a/lib/compiler/src/sys_pre_expand.erl +++ b/lib/compiler/src/sys_pre_expand.erl @@ -232,9 +232,18 @@ pattern({map,Line,Ps}, St0) -> {TPs,St1} = pattern_list(Ps, St0), {{map,Line,TPs},St1}; pattern({map_field_exact,Line,K0,V0}, St0) -> - {K,St1} = expr(K0, St0), + %% Key should be treated as an expression + %% but since expressions are not allowed yet, + %% process it through pattern .. and handle assoc + %% (normalise unary op integer -> integer) + {K,St1} = pattern(K0, St0), {V,St2} = pattern(V0, St1), {{map_field_exact,Line,K,V},St2}; +pattern({map_field_assoc,Line,K0,V0}, St0) -> + %% when keys are Maps + {K,St1} = pattern(K0, St0), + {V,St2} = pattern(V0, St1), + {{map_field_assoc,Line,K,V},St2}; %%pattern({struct,Line,Tag,Ps}, St0) -> %% {TPs,TPsvs,St1} = pattern_list(Ps, St0), %% {{tuple,Line,[{atom,Line,Tag}|TPs]},TPsvs,St1}; |