ndmitchell / hlint

Haskell source code suggestions
Other
1.48k stars 195 forks source link

False positive with lambda case #1502

Closed NorfairKing closed 10 months ago

NorfairKing commented 1 year ago

Given this code:

-- | Get booking settings, 'Nothing' when booking is not configured or the user does not exist.
clientGetBookingSettingsMaybe :: Username -> ClientM (Maybe BookingSettings)
clientGetBookingSettingsMaybe username =
  (Just <$> clientGetBookingSettings username)
    `catchError` ( \err -> case err of
                     FailureResponse _ response ->
                       if responseStatusCode response == HTTP.notFound404
                         then pure Nothing
                         else throwError err
                     err -> throwError err
                 )

I get this lint:

smos-client/src/Smos/Client.hs:(80,20)-(85,42): Suggestion: Use lambda-case
Found:
  \ err
    -> case err of
         FailureResponse _ response
           -> if responseStatusCode response == HTTP.notFound404 then
                  pure Nothing
              else
                  throwError err
         err -> throwError err
Perhaps:
  \case
    FailureResponse _ response
      -> if responseStatusCode response == HTTP.notFound404 then
             pure Nothing
         else
             throwError err
    err -> throwError err

But if I apply this hint, the first occurrance of err is now no longer a bound variable.

zliu41 commented 1 year ago

Thanks for the bug report. This is fixed in #1506.