From: Ian Lynagh Date: Thu, 25 Sep 2008 16:56:18 +0000 (+0000) Subject: Fix the behaviour of flags like --help and --version; fixes trac #2620 X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=commitdiff_plain;h=f599bad1330a08f66c20fa1c9094964234efcb52 Fix the behaviour of flags like --help and --version; fixes trac #2620 They should override other mode flags, not conflict with them --- diff --git a/ghc/Main.hs b/ghc/Main.hs index 0ef2173..557c7ce 100644 --- a/ghc/Main.hs +++ b/ghc/Main.hs @@ -450,10 +450,21 @@ updateDoEval expr _ = DoEval [expr] updateMode :: (CmdLineMode -> CmdLineMode) -> String -> ModeM () updateMode f flag = do (old_mode, old_flag, flags') <- getCmdLineState - if notNull old_flag && flag /= old_flag - then ghcError (UsageError + let new_mode = f old_mode + if null old_flag || flag == old_flag || overridingMode new_mode + then putCmdLineState (new_mode, flag, flags') + else if overridingMode old_mode then return () + else ghcError (UsageError ("cannot use `" ++ old_flag ++ "' with `" ++ flag ++ "'")) - else putCmdLineState (f old_mode, flag, flags') + +-- This returns true for modes that override other modes, e.g. +-- "--interactive --help" and "--help --interactive" are both equivalent +-- to "--help" +overridingMode :: CmdLineMode -> Bool +overridingMode ShowUsage = True +overridingMode ShowVersion = True +overridingMode ShowNumVersion = True +overridingMode _ = False addFlag :: String -> ModeM () addFlag s = do