aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2017-08-29 18:02:49 +0200
committerBjörn Gustavsson <[email protected]>2017-08-30 06:17:14 +0200
commit4c31fd0b966571508b4eb5170ddb0b38fbaf5fc0 (patch)
tree109e3ef2e94b9b5123e4b065a3226cfede9cee28 /lib
parent614cc9aba105f6fe5c72de356be4735c22579ca2 (diff)
downloadotp-4c31fd0b966571508b4eb5170ddb0b38fbaf5fc0.tar.gz
otp-4c31fd0b966571508b4eb5170ddb0b38fbaf5fc0.tar.bz2
otp-4c31fd0b966571508b4eb5170ddb0b38fbaf5fc0.zip
Make handling of match contexts stricter
beam_validator could fail issue a diagnostic when a register that was supposed to be a match context was not guaranteed to be a match context. The bug was in merging of types. Merging of a match context with another term would result in a match context. That is wrong. Merging should produce a more general type, not a narrower type. Also, the valid slots in two match contexts should be combined with 'band', not 'bor'.
Diffstat (limited to 'lib')
-rw-r--r--lib/compiler/src/beam_validator.erl14
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/compiler/src/beam_validator.erl b/lib/compiler/src/beam_validator.erl
index 622e00bb2b..00901077d3 100644
--- a/lib/compiler/src/beam_validator.erl
+++ b/lib/compiler/src/beam_validator.erl
@@ -1430,13 +1430,13 @@ merge_types(bool, {atom,A}) ->
merge_bool(A);
merge_types({atom,A}, bool) ->
merge_bool(A);
-merge_types(#ms{id=Id,valid=B0,slots=Slots}=M,
- #ms{id=Id,valid=B1,slots=Slots}) ->
- M#ms{valid=B0 bor B1,slots=Slots};
-merge_types(#ms{}=M, _) ->
- M;
-merge_types(_, #ms{}=M) ->
- M;
+merge_types(#ms{id=Id1,valid=B0,slots=Slots},
+ #ms{id=Id2,valid=B1,slots=Slots}) ->
+ Id = if
+ Id1 =:= Id2 -> Id1;
+ true -> make_ref()
+ end,
+ #ms{id=Id,valid=B0 band B1,slots=Slots};
merge_types(T1, T2) when T1 =/= T2 ->
%% Too different. All we know is that the type is a 'term'.
term.