aboutsummaryrefslogtreecommitdiffstats
path: root/lib/observer/src/cdv_gen_cb.erl
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2015-01-15 17:17:11 +0100
committerBjörn Gustavsson <[email protected]>2015-01-26 13:08:11 +0100
commita1243173ed98d1006914337b94f28c9594bd8b02 (patch)
tree210c6efaaedc38ad7b91efa04a7db0e8ea7baf44 /lib/observer/src/cdv_gen_cb.erl
parent62c1dd9d9994367da43212f1b33c9e2dacb27e4b (diff)
downloadotp-a1243173ed98d1006914337b94f28c9594bd8b02.tar.gz
otp-a1243173ed98d1006914337b94f28c9594bd8b02.tar.bz2
otp-a1243173ed98d1006914337b94f28c9594bd8b02.zip
Fix handling of binary map keys in comprehensions
The translation of list comprehension with a map pattern with a big literal binary as key such as: lc(L) -> [V || #{<<2:301>> := V} <- L]. would generate Core Erlang code where an unbound variable were referenced: 'lc'/1 = fun (L) -> letrec 'lc$^0'/1 = fun (_cor4) -> case _cor4 of <[~{~<_cor1,V>}~|_cor3]> when 'true' -> let <_cor5> = apply 'lc$^0'/1(_cor3) in [V|_cor5] <[_cor2|_cor3]> when 'true' -> apply 'lc$^0'/1(_cor3) <[]> when 'true' -> [] end in let <_cor1> = #{#<2>(301,1,'integer',['unsigned'|['big']])}# in apply 'lc$^0'/1(L) In the map pattern in the 'case' in the 'letrec', the key is the variable '_cor1' which should be bound in the enclosing environment. It is not. There is binding of '_cor1', but in the wrong place (at the end of the function). Because of the way v3_kernel translates letrecs, the code *happens* to work. The code will break if Core Erlang optimizations were strengthened to more aggressively eliminate variable bindings that are not used, or if the translation from Core Erlang to Kernel Erlang were changed. Correct the translation so that '_cor1' is bound in the environment enclosing the 'letrec': 'lc'/1 = fun (L) -> let <_cor1> = #{#<2>(301,1,'integer',['unsigned'|['big']])}# in letrec 'lc$^0'/1 = fun (_cor4) -> case _cor4 of <[~{~<_cor1,V>}~|_cor3]> when 'true' -> let <_cor5> = apply 'lc$^0'/1(_cor3) in [V|_cor5] <[_cor2|_cor3]> when 'true' -> apply 'lc$^0'/1(_cor3) <[]> when 'true' -> [] end in apply 'lc$^0'/1(L) Unfortunately I was not able to come up with a test case that demonstrates the bug.
Diffstat (limited to 'lib/observer/src/cdv_gen_cb.erl')
0 files changed, 0 insertions, 0 deletions