Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change parsers to use flag' instead of switch #4067

Merged
merged 2 commits into from
Jun 12, 2018

Conversation

markus1189
Copy link
Contributor

This fixes #3959.

The problem is that the switch function returns a Just False which gets wrapped into First.

This means that the value is always set to either True or False
and the First monoid means that during options parsing the order of
the flags suddenly matters as described in #3959, because First (Just False) is chosen when mappending with First (Just True).

The fix is to use the flag function that does not set a default value, so we get a First Nothing instead.

Note: Documentation fixes for https://docs.haskellstack.org/en/stable/ should target the "stable" branch, not master.

Please include the following checklist in your PR:

  • Any changes that could be relevant to users have been recorded in the ChangeLog.md
    there should be no user relevant changes
  • The documentation has been updated, if necessary.
    no relevant changes

Please also shortly describe how you tested your change. Bonus points for added tests!
There is a new integration test in the 3959-order-of-flags folder that makes sure that the order does not matter.

@@ -0,0 +1,2 @@
main :: IO ()
main = putStrLn "Test suite not yet implemented"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make this a failing line so we're sure that the test suite isn't run?

@@ -0,0 +1,65 @@
# This file was automatically generated by 'stack init'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you replace this with resolver: lts-11.6

@@ -0,0 +1,6 @@
module Lib
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should work to drop this module.

@@ -0,0 +1,61 @@
-- This file has been generated from package.yaml by hpack version 0.28.2.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend replacing this .cabal file with a package.yaml file instead.

@@ -0,0 +1,6 @@
module Main where
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be dropped too.

@@ -0,0 +1,2 @@
import Distribution.Simple
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be dropped too.

@@ -19,7 +19,7 @@ benchOptsParser hide0 = BenchmarkOptsMonoid
help ("Forward BENCH_ARGS to the benchmark suite. " <>
"Supports templates from `cabal bench`") <>
hide))
<*> optionalFirst (switch (long "no-run-benchmarks" <>
<*> optionalFirst (flag' True (long "no-run-benchmarks" <>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment to the changelog about the bugfix?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

This fixes commercialhaskell#3959.

The problem is that the [switch](https://hackage.haskell.org/package/optparse-applicative/docs/Options-Applicative-Builder.html#v:switch) function returns a `Just False` which gets wrapped into `First`.

This means that the value is *always* set to either `True` or `False`
and the `First` monoid means that during options parsing the order of
the flags suddenly matters as described in commercialhaskell#3959, because `First (Just
False)` is chosen when `mappend`ing with `First (Just True)`.

The fix is to use the [flag](https://hackage.haskell.org/package/optparse-applicative-0.14.2.0/docs/Options-Applicative-Builder.html#v:flag-39-) function that does not set a default value, so we get a `First Nothing` instead.
@snoyberg snoyberg merged commit bf8ad2f into commercialhaskell:master Jun 12, 2018
@snoyberg
Copy link
Contributor

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

It should not matter if flags given before command or after
3 participants