diff options
author | Paolo Capriotti <p.capriotti@gmail.com> | 2012-08-13 12:48:29 +0100 |
---|---|---|
committer | Paolo Capriotti <p.capriotti@gmail.com> | 2012-08-13 12:48:29 +0100 |
commit | f78b31a36b5b49afbdea199269319faca261c898 (patch) | |
tree | 4f560c985bea63925fbdc90928753bb6131af91e | |
parent | 7473c3d291742175e2e2a4ba98f0c1dba5393599 (diff) | |
download | haskell-f78b31a36b5b49afbdea199269319faca261c898.tar.gz |
Fix ambiguous flag resolution (#7138)
Pick longest flag when more than one matches in findArg.
This fixes an issue where -ignore-dot-ghci wasn't honored, because the
flag was parsed as "-i gnore-dot-ghci".
-rw-r--r-- | compiler/main/CmdLineParser.hs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/compiler/main/CmdLineParser.hs b/compiler/main/CmdLineParser.hs index c6d07ce027..f87039a2e5 100644 --- a/compiler/main/CmdLineParser.hs +++ b/compiler/main/CmdLineParser.hs @@ -27,6 +27,7 @@ import Panic import Bag import SrcLoc +import Data.Function import Data.List @@ -194,11 +195,12 @@ processOneArg opt_kind rest arg args findArg :: [Flag m] -> String -> Maybe (String, OptKind m) findArg spec arg = - case [ (removeSpaces rest, optKind) - | flag <- spec, - let optKind = flagOptKind flag, - Just rest <- [stripPrefix (flagName flag) arg], - arg_ok optKind rest arg ] + case sortBy (compare `on` (length . fst)) -- prefer longest matching flag + [ (removeSpaces rest, optKind) + | flag <- spec, + let optKind = flagOptKind flag, + Just rest <- [stripPrefix (flagName flag) arg], + arg_ok optKind rest arg ] of [] -> Nothing (one:_) -> Just one |