1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module Check.AST.Pattern.ThenTrueElseFalse where

import Curry.SpanInfo
import Curry.Span
import Curry.Position
import Curry.Types
import Curry.Ident
import Text.Pretty

import Types

-- per patternmatching apply actual check only on ifthenelse constructs
checkThenTrueElseFalse :: Expression a -> Int -> CSM ()
checkThenTrueElseFalse e _ =
  case e of
    (IfThenElse sI _
      (Constructor _ _ (QualIdent _ _ (Ident _ "True" _)))
      (Constructor _ _ (QualIdent _ _ (Ident _ "False" _)))) -> checkThenTrueElseFalse' sI "not "
    (IfThenElse sI _
      (Constructor _ _ (QualIdent _ _ (Ident _ "False" _)))
      (Constructor _ _ (QualIdent _ _ (Ident _ "True" _))))  -> checkThenTrueElseFalse' sI ""
    _                                                        -> return ()

-- report
checkThenTrueElseFalse' :: SpanInfo -> String -> CSM ()
checkThenTrueElseFalse' (SpanInfo sp sps) s =
  report ( Message
           sp
           ( text "superfluous code"
           <+> colorizeKey "then bool else not (bool)"
           )
           ( text "write instead of if"
           <+> colorizeKey "condition"
           <+> text "then True (False) else False (True) just "
           <+> colorizeKey (s ++ "condition")
           )
         )