coala / coala-bears

Bears for coala
https://coala.io/
GNU Affero General Public License v3.0
294 stars 580 forks source link

HaskellLintBear throws assertionFailure exceptions #2903

Open WeeBull opened 5 years ago

WeeBull commented 5 years ago

When running HaskellLintBear on the following code:

wrapAsteroidP :: V2 Float -> V2 Float
wrapAsteroidP p = fmap f p
  where f x = if (x < (-worldSize))
              then x + (2 * worldSize)
              else if (x > worldSize)
                   then x - (2 * worldSize)
                   else x

...we get the exception:

[DEBUG][14:51:32] Running 'hlint --json /home/pauls/HAsteroids/src/Asteroid.hs'
[DEBUG][14:51:32] The bear HaskellLintBear raised an exception. If you are the author of this bear, please make sure to catch all exceptions. If not and this error annoys you, you might want to get in contact with the author of this bear.

Traceback information is provided below:

Traceback (most recent call last):
  File "/home/pauls/.local/lib/python3.7/site-packages/coalib/bears/Bear.py", line 282, in execute
    return [] if result is None else list(result)
  File "/home/pauls/.local/lib/python3.7/site-packages/bears/haskell/HaskellLintBear.py", line 44, in process_output
    assert len(from_lines) == len(to_lines)
AssertionError

This appears to be because the change hlint is suggesting is multi-line, with the result being longer than the original.

src/Asteroid.hs:69:9: Suggestion: Use guards
Found:
  f x
    = if (x < (-worldSize)) then x + (2 * worldSize) else
        if (x > worldSize) then x - (2 * worldSize) else x
Why not:
  f x
    | (x < (-worldSize)) = x + (2 * worldSize)
    | (x > worldSize) = x - (2 * worldSize)
    | otherwise = x

The JSON returned by hlint is:

{
    "module": "Asteroid",
    "decl": "wrapAsteroidP",
    "severity": "Suggestion",
    "hint": "Use guards",
    "file": "src/Asteroid.hs",
    "startLine": 69,
    "startColumn": 9,
    "endLine": 73,
    "endColumn": 26,
    "from": "f x\n  = if (x < (-worldSize)) then x + (2 * worldSize) else\n      if (x > worldSize) then x - (2 * worldSize) else x",
    "to": "f x\n  | (x < (-worldSize)) = x + (2 * worldSize)\n  | (x > worldSize) = x - (2 * worldSize)\n  | otherwise = x",
    "note": [],
    "refactorings": "[Replace {rtype = Match, pos = SrcSpan {startLine = 69, startCol = 9, endLine = 73, endCol = 26}, subts = [(\"g1001\",SrcSpan {startLine = 69, startCol = 18, endLine = 69, endCol = 36}),(\"g1002\",SrcSpan {startLine = 71, startCol = 23, endLine = 71, endCol = 38}),(\"e1001\",SrcSpan {startLine = 70, startCol = 20, endLine = 70, endCol = 39}),(\"e1002\",SrcSpan {startLine = 72, startCol = 25, endLine = 72, endCol = 44}),(\"e1003\",SrcSpan {startLine = 73, startCol = 25, endLine = 73, endCol = 26})], orig = \"f x\n  | g1001 = e1001\n  | g1002 = e1002\n  | otherwise = e1003\"}]"
},