Skip to content

Commit d1a2ba9

Browse files
committed
Fix a variable renaming bug in normalized ABT
Renamed bound variables weren't being freshened against the right set of other variables. It seems renaming was never used in a situation where this mattered before, though.
1 parent a56abf7 commit d1a2ba9

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

unison-core/src/Unison/ABT/Normalized.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,19 @@ renames0 subvs0 rnv0 tm = case tm of
152152
| not $ Map.null rnv' -> TAbs u' (renames0 subvs' rnv' body)
153153
where
154154
rnv' = Map.alter (const $ adjustment) u rnv
155+
bfvs = freeVars body
155156
-- if u is in the set of variables we're substituting in, it
156157
-- needs to be renamed to avoid capturing things.
157158
u'
158-
| u `Map.member` subvs = freshIn (fvs `Set.union` Map.keysSet subvs) u
159+
| u `Map.member` subvs = freshIn (bfvs `Set.union` Map.keysSet subvs) u
159160
| otherwise = u
160161

161162
-- if u needs to be renamed to avoid capturing subvs
162163
-- and u actually occurs in the body, then add it to
163164
-- the substitutions
164165
(adjustment, subvs')
165-
| u /= u' && u `Set.member` fvs = (Just u', Map.insertWith (+) u' 1 subvs)
166+
| u /= u' && u `Set.member` bfvs =
167+
(Just u', Map.insertWith (+) u' 1 subvs)
166168
| otherwise = (Nothing, subvs)
167169
TTm body
168170
| not $ Map.null rnv ->

0 commit comments

Comments
 (0)