Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applying HLint Suggestions does not work properly #33

Closed
k0aaa opened this issue Dec 9, 2017 · 5 comments
Closed

Applying HLint Suggestions does not work properly #33

k0aaa opened this issue Dec 9, 2017 · 5 comments

Comments

@k0aaa
Copy link
Contributor

k0aaa commented Dec 9, 2017

Sometimes it doesnt delete the old code and just append everything after the entire code block

--getInts = fmap (map read . words) getLine
getInts = fmap ((map read). words) getLine

turns into

--getInts = fmap (map read . words) getLine
getInts = fmap ((map read). words) getLine--getInts = fmap (map read . words) getLine

getInts = fmap (map read. words) getLine

and another one:

main :: IO ()
countFac :: Int -> Int -> Int

main = do
    getLine
    a_temp <- getLine
    let a = map read $ words a_temp :: [Int]
    b_temp <- getLine
    let b = map read $ words b_temp :: [Int]
    let l = foldl lcm (head a) (tail a) --THIS LINE IS TO BE REPLACED WITH foldl1
    let g = foldl1 gcd b
    let s = g `div` l
    if s * l /= g
        then do
            print 0
            return ()
        else do
    print (countFac s 1)
    return ()

countFac n c
    | c > n `div` 2 = 1
    | n `div` c * c == n = 1 + countFac n (c+1)
    | otherwise = countFac n (c+1)

turns into

main :: IO ()
countFac :: Int -> Int -> Int

main = do ---THE getLine HERE IS MISSING
    a_temp <- getLine
    let a = map read $ words a_temp :: [Int]
    b_temp <- getLine
    let b = map read $ words b_temp :: [Int]
    let l = foldl lcm (head a) (tail a) --IT'S STILL HERE
    let g = foldl1 gcd b
    let s = g `div` l
    if s * l /= g
        then do
            print 0
            return ()
        else do
    let l = foldl1 lcm a -- IT GOT APPENDED HERE
countFac n c
    | c > n `div` 2 = 1
    | n `div` c * c == n = 1 + countFac n (c+1)
    | otherwise = countFac n (c+1)

I'm using Caps so that it would be easier to locate them

@nponeccop
Copy link

nponeccop commented Dec 9, 2017

Interestingly if I use hlint --refact I get the correct output. Here is the diff:

diff --git a/bar.hs b/bar.hs
index 8a402a0..5c04dd0 100644
--- a/bar.hs
+++ b/bar.hs
@@ -7,7 +7,7 @@ main = do
     let a = map read $ words a_temp :: [Int]
     b_temp <- getLine
     let b = map read $ words b_temp :: [Int]
-    let l = foldl lcm (head a) (tail a) --THIS LINE IS TO BE REPLACED WITH foldl1
+    let l = foldl1 lcm a --THIS LINE IS TO BE REPLACED WITH foldl1
     let g = foldl1 gcd b
     let s = g `div` l
     if s * l /= g

I installed hlint and refact using stack.yaml, so they are of exactly the same version HIE gets for GHC 8.0.2.

The steps to reproduce are:

  • go to hie build folder
  • run stack install hlint refact, appending --stack-yaml= if necessary
  • if you did it correctly then only a few things get rebuilt as we basically add 2 executable targets
  • create bar.hs with the second example from this report
  • run git add bar.hs so it's easy to get a diff later on
  • run hlint bar.hs --refactor --refactor-options="--inplace"
  • run git diff bar.hs
  • unstage bar.hs by git reset HEAD bar.hs and delete it

@k0aaa
Copy link
Contributor Author

k0aaa commented Dec 10, 2017

So you failed with the VS code addon?
BTW by me it said hlint.exe:cound not find refactor
So installed apply-refact and hlint works yet it still doesnt work with the HIE plugin.
------
So The HIE works fine with Sublime Text, so it has to be the addon's problem

@nponeccop
Copy link

nponeccop commented Dec 10, 2017

I didn't try VS code. I only checked bare hlint --refactor command line and it worked.

BTW by me it said hlint.exe:cound not find refactor

Oh, it should have been "stack install hlint apply-refact"

https://github.com/mpickering/apply-refact package installs refact library and refact.exe executable which is used by hlint.

@k0aaa k0aaa closed this as completed Dec 18, 2017
@nponeccop
Copy link

You should state why the bug is closed (for future readers)

@k0aaa
Copy link
Contributor Author

k0aaa commented Dec 19, 2017

Cuz this is not a problem on this side

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants