hlint icon indicating copy to clipboard operation
hlint copied to clipboard

Incorrect redundant bracket warning with OverloadedRecordDot

Open AriFordsham opened this issue 2 years ago • 2 comments

given

newtype T = T { f :: B }

g :: A -> T
a :: A

The code

(g a).f

uses the record dot operator. HLint recognizes this as the compose operator and incorrectly warns of a redundant bracket. Removing the bracket breaks the code, of course.

AriFordsham avatar Feb 13 '23 15:02 AriFordsham

Hey, I have tried to reproduce this error and am having trouble. Calling hlint on the following file:

{-# LANGUAGE OverloadedRecordDot #-}

newtype T = T { f :: B }

g :: A -> T

f :: A -> B
f a = (g a).f

yields the following error:

Warning: Avoid restricted extensions
Found:
  {-# LANGUAGE OverloadedRecordDot #-}
Note: may break the code

When the language extension is removed, the following error is produced:

Suggestion: Redundant bracket
Found:
  (g a) . f
Perhaps:
  g a . f

I believe this suggestion is correct, as without the extension, the . is interpreted as composition. Perhaps an update was pushed to master in the time since this has been opened that has resolved the problem?

benbellick avatar Mar 23 '23 03:03 benbellick

Confirming that this seems to have been fixed in hlint-3.4.1 (the one which I tested). One needs to have the LANGUAGE OverloadedRecordDot in the file (as opposed to putting it into the package configuration) or call hlint with -XOverloadedRecordDot. I am BTW not getting the Avoid restricted extension warning with hlint-3.4.1.

jberthold avatar Mar 24 '23 05:03 jberthold