GetOpt bug causing it to mistakenly reject options as ambiguous

Eelis van der Weegen haskell-libs at contacts.eelis.net
Fri Mar 7 08:16:07 EST 2008


[This is a resend; I tried to post through gmane but the message never arrived.]

There is a bug in System.Console.GetOpt causing it to mistakenly reject
options as ambiguous.

Testcase:

> import System.Console.GetOpt
>
> type Color = String
>
> optsDesc :: [OptDescr Color]
> optsDesc = [Option "" ["color", "colour"] (ReqArg id "color") "Foreground color"]
>
> main = do
>   let args = ["--col=blue"]
>   case getOpt RequireOrder optsDesc args of
>     (_, _, err:_) -> putStrLn err
>     _ -> return ()

Output:

  option `--col' is ambiguous; could be one of:
      --color=color, --colour=color  Foreground color
      --color=color, --colour=color  Foreground color

This error is silly, because the two alternatives listed are the same
option.

The problem is caused by incorrect use of a generator in a list
comprehension.

I've attached a patch that fixes the problem.

Regards,

Eelis
-------------- next part --------------
A non-text attachment was scrubbed...
Name: GetOpt.hs.diff
Type: text/x-patch
Size: 861 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/libraries/attachments/20080307/f63eba78/GetOpt.hs.bin


More information about the Libraries mailing list