diff options
author | Björn Gustavsson <[email protected]> | 2016-05-18 06:33:33 +0200 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2016-05-20 10:07:17 +0200 |
commit | aa30fb09bca19916c82c239ce4d21897897a1b03 (patch) | |
tree | 41b3a6740d1a7d5e2dd5f5c5f24b70e73f464d66 | |
parent | 37b60d5b365e814c83974cdac0f1eed04dab0ad3 (diff) | |
download | otp-aa30fb09bca19916c82c239ce4d21897897a1b03.tar.gz otp-aa30fb09bca19916c82c239ce4d21897897a1b03.tar.bz2 otp-aa30fb09bca19916c82c239ce4d21897897a1b03.zip |
beam_validator: Keep better track of tuple literals
As a preparation for upcoming better optimizations in beam_type,
we will need to keep better track of tuple literals so that
beam_validator will not falsely reject safe code.
-rw-r--r-- | lib/compiler/src/beam_validator.erl | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/compiler/src/beam_validator.erl b/lib/compiler/src/beam_validator.erl index 6877141885..d53aff004f 100644 --- a/lib/compiler/src/beam_validator.erl +++ b/lib/compiler/src/beam_validator.erl @@ -1165,12 +1165,15 @@ assert_type(WantedType, Term, Vst) -> assert_type(Correct, Correct) -> ok; assert_type(float, {float,_}) -> ok; assert_type(tuple, {tuple,_}) -> ok; +assert_type(tuple, {literal,Tuple}) when is_tuple(Tuple) -> ok; assert_type({tuple_element,I}, {tuple,[Sz]}) when 1 =< I, I =< Sz -> ok; assert_type({tuple_element,I}, {tuple,Sz}) when is_integer(Sz), 1 =< I, I =< Sz -> ok; +assert_type({tuple_element,I}, {literal,Lit}) when I =< tuple_size(Lit) -> + ok; assert_type(Needed, Actual) -> error({bad_type,{needed,Needed},{actual,Actual}}). @@ -1549,8 +1552,12 @@ return_type_1(erlang, setelement, 3, Vst) -> Tuple = {x,1}, TupleType = case get_term_type(Tuple, Vst) of - {tuple,_}=TT -> TT; - _ -> {tuple,[0]} + {tuple,_}=TT -> + TT; + {literal,Lit} when is_tuple(Lit) -> + {tuple,tuple_size(Lit)}; + _ -> + {tuple,[0]} end, case get_term_type({x,0}, Vst) of {integer,[]} -> TupleType; |