-
Notifications
You must be signed in to change notification settings - Fork 842
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
Change parsers to use flag'
instead of switch
#4067
Conversation
98d25ce
to
29a87d2
Compare
@@ -0,0 +1,2 @@ | |||
main :: IO () | |||
main = putStrLn "Test suite not yet implemented" |
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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" <> |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
29a87d2
to
7d50f47
Compare
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.
7d50f47
to
bf4711e
Compare
Thanks! |
This fixes #3959.
The problem is that the switch function returns a
Just False
which gets wrapped intoFirst
.This means that the value is always set to either
True
orFalse
and the
First
monoid means that during options parsing the order ofthe flags suddenly matters as described in #3959, because
First (Just False)
is chosen whenmappend
ing withFirst (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:
there should be no user relevant changes
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.