ennocramer / floskell

Floskell is a flexible Haskell source code pretty printer.
BSD 3-Clause "New" or "Revised" License
178 stars 22 forks source link

floskell produces incorrect code #44

Closed harendra-kumar closed 4 years ago

harendra-kumar commented 4 years ago

This

consM :: Monad m => m a -> Stream m a -> Stream m a
consM m (Stream step state) = Stream step1 Nothing
    where
    {-# INLINE_LATE step1 #-}
    step1 _ Nothing   = m >>= \x -> return $ Yield x (Just state)
    step1 gst (Just st) = do
        r <- step gst st

becomes this

consM :: Monad m => m a -> Stream m a -> Stream m a
consM m (Stream step state) = Stream step1 Nothing
    {-# INLINE_LATE step1 #-}
        where
        step1 _ Nothing     = m >>= \x -> return $ Yield x (Just state)
        step1 gst (Just st) = do
            r <- step gst st

Notice the INLINE going above the where keyword. It seems this has been fixed in hindent.

ennocramer commented 4 years ago

This seems to be a problem with haskell-src-exts where the span information for the where block does not include the where keyword. This leads to floskell thinking the comment is before the entire where block, instead of before the declaration of step1. I'm looking into haskell-src-exts to see if I can find a fix.

ennocramer commented 4 years ago

I should not have blamed haskell-src-exts. It's rather a misunderstanding on my part as to which syntactical entity the where keyword belongs.

The problem is fixed in master as of 99cc2a19f6b2f865ae85c09cfcc3ce156f5ade22.

ennocramer commented 4 years ago

Released with floskell-0.10.4.