Commit f78b31a3 authored by pcapriotti's avatar pcapriotti
Browse files

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".
parent 7473c3d2
...@@ -27,6 +27,7 @@ import Panic ...@@ -27,6 +27,7 @@ import Panic
import Bag import Bag
import SrcLoc import SrcLoc
import Data.Function
import Data.List import Data.List
...@@ -194,11 +195,12 @@ processOneArg opt_kind rest arg args ...@@ -194,11 +195,12 @@ processOneArg opt_kind rest arg args
findArg :: [Flag m] -> String -> Maybe (String, OptKind m) findArg :: [Flag m] -> String -> Maybe (String, OptKind m)
findArg spec arg = findArg spec arg =
case [ (removeSpaces rest, optKind) case sortBy (compare `on` (length . fst)) -- prefer longest matching flag
| flag <- spec, [ (removeSpaces rest, optKind)
let optKind = flagOptKind flag, | flag <- spec,
Just rest <- [stripPrefix (flagName flag) arg], let optKind = flagOptKind flag,
arg_ok optKind rest arg ] Just rest <- [stripPrefix (flagName flag) arg],
arg_ok optKind rest arg ]
of of
[] -> Nothing [] -> Nothing
(one:_) -> Just one (one:_) -> Just one
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment