More aggressive freshening to avoid shadowing issues
This commit is contained in:
parent
63d51baaa3
commit
c8153f94a6
@ -1680,9 +1680,19 @@ bottom_up(F, Env, Expr) ->
|
|||||||
{switch, Split} -> {switch, bottom_up(F, Env, Split)};
|
{switch, Split} -> {switch, bottom_up(F, Env, Split)};
|
||||||
{lam, Xs, B} -> {lam, Xs, bottom_up(F, Env, B)};
|
{lam, Xs, B} -> {lam, Xs, bottom_up(F, Env, B)};
|
||||||
{'let', X, E, Body} ->
|
{'let', X, E, Body} ->
|
||||||
E1 = bottom_up(F, Env, E),
|
E1 = bottom_up(F, Env, E),
|
||||||
Env1 = Env#{ X => E1 },
|
%% Always freshen user variables to avoid shadowing issues.
|
||||||
{'let', X, E1, bottom_up(F, Env1, Body)};
|
ShouldFreshen = fun(Y = "%" ++ _) -> maps:is_key(Y, Env);
|
||||||
|
(_) -> true end,
|
||||||
|
case ShouldFreshen(X) of
|
||||||
|
true ->
|
||||||
|
Z = fresh_name(),
|
||||||
|
Env1 = Env#{ Z => E1 },
|
||||||
|
{'let', Z, E1, bottom_up(F, Env1, rename([{X, Z}], Body))};
|
||||||
|
false ->
|
||||||
|
Env1 = Env#{ X => E1 },
|
||||||
|
{'let', X, E1, bottom_up(F, Env1, Body)}
|
||||||
|
end;
|
||||||
{split, Type, X, Cases} -> {split, Type, X, [bottom_up(F, Env, Case) || Case <- Cases]};
|
{split, Type, X, Cases} -> {split, Type, X, [bottom_up(F, Env, Case) || Case <- Cases]};
|
||||||
{nosplit, E} -> {nosplit, bottom_up(F, Env, E)};
|
{nosplit, E} -> {nosplit, bottom_up(F, Env, E)};
|
||||||
{'case', Pat, Split} -> {'case', Pat, bottom_up(F, Env, Split)}
|
{'case', Pat, Split} -> {'case', Pat, bottom_up(F, Env, Split)}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user