Skip to content

Hlint "Expected type not found at the location specified in the refact file." error in certain circumstances when refactoring #2612

Closed
@FreyrDev

Description

@FreyrDev

Your environment

Which OS do you use:
- Windows
Which LSP client (editor/plugin) do you use:
- VS Code
Describe your project (alternative: link to the project):
- GHC 8.10.7, Cabal 3.6.2.0

Steps to reproduce

Create a new .hs file with this code:

import Data.List (sortOn)
import Control.Arrow ((&&&))
import Data.Ord (Down(Down))

functionA :: [String] -> [(Char,Int)]
functionA = reverse . sortOn snd . map (head &&& length)

functionB :: [String] -> [(Char,Int)]
functionB = reverse . sortOn snd . map (head &&& length) . id

Both functions will be highlighted by hlint telling you to avoid using the reverse
Use the quick fix feature (Ctrl+. in VS Code) to apply the refactor on each function

Expected behaviour

The error should not appear, and the avoid reverse refactor should produce the same code with either function:

functionB = sortOn (Down . snd) . map (head &&& length) . id

Actual behaviour

Using the quick fix while the cursor is on the body of functionA will refactor the code as expected
However using the Quick Fix while the cursor is on the body of functionB will produce the follwing error:

hlint:applyOne: "Expected type not found at the location specified in the refact file.\n Expected type: HsExpr (GhcPass 'Parsed)\n Location: C:\\Users\\<username>\\Personal\\Hobbies\\Programming\\test.hs:9:36-61: inappropriate type"

Additonally the redundant id suggested refactor doesn't do anything at all in this circumstance.

Include debug information

Extended error message from the logs:

[2022-01-20 02:12:51.997] [exthost] [error] Error: hlint:applyOne: "Expected type not found at the location specified in the refact file.\n  Expected type: HsExpr (GhcPass 'Parsed)\n  Location: C:\\Users\\<username>\\Personal\\Hobbies\\Programming\\test.hs:9:36-61: inappropriate type"
	at c:\Users\<username>\.vscode\extensions\haskell.haskell-1.8.0\dist\extension.js:2:1005073
	at c:\Users\<username>\.vscode\extensions\haskell.haskell-1.8.0\dist\extension.js:2:1005367
	at Immediate.<anonymous> (c:\Users\<username>\.vscode\extensions\haskell.haskell-1.8.0\dist\extension.js:2:1005732)
	at processImmediate (internal/timers.js:461:21) 7804:hlint:applyOne undefined

Metadata

Metadata

Assignees

No one assigned

    Labels

    component: hls-hlint-plugintype: bugSomething isn't right: doesn't work as intended, documentation is missing/outdated, etc..

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions