haskell / haskell/haskell-language-server

Bogus errors/warnings on Num literals

Open
#3,158 9 comments 0 reactions 0 assignees View on GitHub
component: hls-alternate-number-format-plugin type: bug
Dominant language
Haskell
Stars
3k
Forks
455
Avg merge
2d 19h
Merged PRs (30d)
11

Description

### Your environment

- MacOS Monterey 12.6
- Xcode-14
- GHC-9.2.4 (also, 9.0.2, 9.4.1)
- Cabal-3.8.1.0
- HLS built from this `master` via `ghcup compile hls --git-ref master --ghc 9.2.4`
- `hlint` v3.3.6
- VS Code with Haskell for VIsual Studio Code v2.2.1
- `haskell-linter` v0.0.6 (an extension to use `hlint` in vscode)

`hie.yaml` file:
```yaml
cradle:
cabal:
- path: "src"
component: "lib:stepic-tests"

- path: "app/Main.hs"
component: "stepic-tests:exe:stepic-tests-exe"

- path: "app/Paths_stepic_tests.hs"
component: "stepic-tests:exe:stepic-tests-exe"

- path: "test"
component: "stepic-tests:test:stepic-tests-test"

- path: "app/MaybeDemo.hs"
component: "stepic-tests:exe:maybe-demo"

- path: "app/Paths_stepic_tests.hs"
component: "stepic-tests:exe:maybe-demo"
```

### Steps to reproduce and Actual behavior

Open a .hs file in VS Code that contains integer literals, such as the following:
```hs
main :: IO ()
main = print $ nextPosN [1] (-1) (\x -> sum x < 7)

nextPosN :: [Int] -> Int -> ([Int] -> Bool) -> [[Int]]
nextPosN = undefined
```
and observe the error (warning, actually):
```
No instance for (Num [Int]) arising from the literal ‘1’
• In the expression: 1
In the first argument of ‘nextPosN’, namely ‘[1]’
In the second argument of ‘($)’, namely
‘nextPosN [1] (- 1) (\ x -> sum x < 7)’
```

Closely related to it is this (GitHub appears to stop allowing uploading screenshot (PNG) images):
```
Quick Fix...
Convert 1 into 0x1
Convert 1 into 0o1
Convert 1 into 1.0e0 (needs extension: NumDecimals)
```

Restarting HLS does not help. Restarting VS Code removes this bogus report, at least for a while.

### Expected behaviour

Not to be told to convert `1` into `0x1`, to begin with. ;-)

More importantly, not to be told that there's `No instance for (Num [Int]) arising from the literal '1'`

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.