Skip to content

Commit 79619e2

Browse files
committed
Try defining subtype(union(), union()) with type_diff()
This solves the problem captured in test/known_problems/should_pass/different_normalization_levels.erl but leads to a lot of other test failures.
1 parent aac8000 commit 79619e2

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

src/typechecker.erl

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -361,15 +361,21 @@ compat_ty({type, _, 'fun', [{type, _, product, Args1}, Res1]},
361361
{Aps, constraints:combine(Cs, Css, Env)};
362362

363363
%% Unions
364-
compat_ty({type, _, union, Tys1}, {type, _, union, Tys2}, Seen, Env) ->
365-
lists:foldl(fun (Ty1, {Seen1, C1}) ->
366-
{Seen2, C2} = any_type(Ty1, Tys2, Seen1, Env),
367-
{Seen2, constraints:combine(C1, C2, Env)}
368-
end, {Seen, constraints:empty()}, Tys1);
369-
compat_ty(Ty1, {type, _, union, Tys2}, Seen, Env) ->
370-
any_type(Ty1, Tys2, Seen, Env);
371-
compat_ty({type, _, union, Tys1}, Ty2, Seen, Env) ->
372-
all_type(Tys1, Ty2, Seen, Env);
364+
compat_ty({type, _, union, _} = U1, {type, _, union, _} = U2, Seen, Env) ->
365+
case type_diff(U1, U2, Env) of
366+
?type(none) -> ret(Seen);
367+
false -> throw(nomatch)
368+
end;
369+
370+
%compat_ty({type, _, union, Tys1}, {type, _, union, Tys2}, Seen, Env) ->
371+
% lists:foldl(fun (Ty1, {Seen1, C1}) ->
372+
% {Seen2, C2} = any_type(Ty1, Tys2, Seen1, Env),
373+
% {Seen2, constraints:combine(C1, C2, Env)}
374+
% end, {Seen, constraints:empty()}, Tys1);
375+
%compat_ty(Ty1, {type, _, union, Tys2}, Seen, Env) ->
376+
% any_type(Ty1, Tys2, Seen, Env);
377+
%compat_ty({type, _, union, Tys1}, Ty2, Seen, Env) ->
378+
% all_type(Tys1, Ty2, Seen, Env);
373379

374380
% Integer types
375381
compat_ty(Ty1, Ty2, Seen, _Env) when ?is_int_type(Ty1), ?is_int_type(Ty2) ->
@@ -608,16 +614,16 @@ any_type(Ty1, Tys, Seen0, Env) ->
608614
%% @doc All types in `Tys' must be compatible with `Ty'.
609615
%% Returns all the gather memoizations and constraints.
610616
%% Does not return (throws `nomatch') if any of the types is not compatible.
611-
-spec all_type([type()], type(), map(), env()) -> compat_acc().
612-
all_type(Tys, Ty, Seen, Env) ->
613-
all_type(Tys, Ty, Seen, [], Env).
614-
615-
-spec all_type([type()], type(), map(), [constraints:t()], env()) -> compat_acc().
616-
all_type([], _Ty, Seen, Css, Env) ->
617-
{Seen, constraints:combine(Css, Env)};
618-
all_type([Ty1|Tys], Ty, AIn, Css, Env) ->
619-
{AOut, Cs} = compat(Ty1, Ty, AIn, Env),
620-
all_type(Tys, Ty, AOut, [Cs|Css], Env).
617+
%-spec all_type([type()], type(), map(), env()) -> compat_acc().
618+
%all_type(Tys, Ty, Seen, Env) ->
619+
% all_type(Tys, Ty, Seen, [], Env).
620+
621+
%-spec all_type([type()], type(), map(), [constraints:t()], env()) -> compat_acc().
622+
%all_type([], _Ty, Seen, Css, Env) ->
623+
% {Seen, constraints:combine(Css, Env)};
624+
%all_type([Ty1|Tys], Ty, AIn, Css, Env) ->
625+
% {AOut, Cs} = compat(Ty1, Ty, AIn, Env),
626+
% all_type(Tys, Ty, AOut, [Cs|Css], Env).
621627

622628
%% Looks up the fields of a record by name and, if present, by the module where
623629
%% it belongs if a filename is included in the Anno.

0 commit comments

Comments
 (0)