RefactoringTools / HaRe

The Haskell Refactoring Tool
http://www.cs.kent.ac.uk/projects/refactor-fp/
Other
139 stars 32 forks source link

Lifting pattern bindings makes variables escape their scope #42

Closed Lysxia closed 7 years ago

Lysxia commented 7 years ago
f x = let (a, b) = (x, x) in a

liftToTopLevel-ing a results in

f x = (a x)

(a, b) = (x, x)

A simple fix is to refuse to lift such declarations, though it might be interesting to implement something less trivial in the future.

f x = a x
a x = fst (x, x)
b x = snd (x, x)
alanz commented 7 years ago

This issue is in fact already captured in the PatBindIn2 test case, which is currently marked as pending

module PatBindIn2 where

--A definition can be lifted from a where or let into the surrounding binding group.
--Lifting a definition widens the scope of the definition.

--In this example, lift 'tup' defined in 'foo' will fail.

main :: Int
main = foo 3

foo :: Int -> Int
foo x = h + t + (snd tup)
      where
      h :: Int
      t :: Int
      tup :: (Int,Int)
      tup@(h,t) = head $ zip [1..x] [3..15]