diff options
author | Daishi Nakajima <nakaji.dayo@gmail.com> | 2017-01-18 16:23:55 -0500 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2017-01-18 17:39:48 -0500 |
commit | 181688abae5c0b32237a5bd783dfc9667641cce2 (patch) | |
tree | f54bf73606eb4315ac4bf1d970af64d0c8c42208 | |
parent | 852c6a09f8ac21c3e843e64dfa7c6382073eb5ce (diff) | |
download | haskell-181688abae5c0b32237a5bd783dfc9667641cce2.tar.gz |
Improve suggestion for misspelled flag including '=' (fixes #11789)
Test Plan:
Added 2 test cases, verified that ghc can suggest in the following
cases:
- for misspelled flag containing '=', ghc suggests flags that doesn't
contain '='
- for misspelled flag containing '=', ghc suggests flags that
contains '='
Reviewers: austin, dfeuer, bgamari
Reviewed By: dfeuer, bgamari
Subscribers: dfeuer, mpickering, thomie
Differential Revision: https://phabricator.haskell.org/D2978
GHC Trac Issues: #11789
-rw-r--r-- | ghc/Main.hs | 11 | ||||
-rw-r--r-- | testsuite/tests/driver/should_fail/T11789a.hs | 1 | ||||
-rw-r--r-- | testsuite/tests/driver/should_fail/T11789a.stderr | 5 | ||||
-rw-r--r-- | testsuite/tests/driver/should_fail/T11789b.hs | 1 | ||||
-rw-r--r-- | testsuite/tests/driver/should_fail/T11789b.stderr | 7 | ||||
-rw-r--r-- | testsuite/tests/driver/should_fail/all.T | 3 |
6 files changed, 27 insertions, 1 deletions
diff --git a/ghc/Main.hs b/ghc/Main.hs index 83d5238176..a650d35a62 100644 --- a/ghc/Main.hs +++ b/ghc/Main.hs @@ -915,9 +915,18 @@ unknownFlagsErr fs = throwGhcException $ UsageError $ concatMap oneError fs where oneError f = "unrecognised flag: " ++ f ++ "\n" ++ - (case fuzzyMatch f (nub allNonDeprecatedFlags) of + (case match f (nubSort allNonDeprecatedFlags) of [] -> "" suggs -> "did you mean one of:\n" ++ unlines (map (" " ++) suggs)) + -- fixes #11789 + -- If the flag contains '=', + -- this uses both the whole and the left side of '=' for comparing. + match f allFlags + | elem '=' f = + let (flagsWithEq, flagsWithoutEq) = partition (elem '=') allFlags + fName = takeWhile (/= '=') f + in (fuzzyMatch f flagsWithEq) ++ (fuzzyMatch fName flagsWithoutEq) + | otherwise = fuzzyMatch f allFlags {- Note [-Bsymbolic and hooks] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/testsuite/tests/driver/should_fail/T11789a.hs b/testsuite/tests/driver/should_fail/T11789a.hs new file mode 100644 index 0000000000..78595d67b9 --- /dev/null +++ b/testsuite/tests/driver/should_fail/T11789a.hs @@ -0,0 +1 @@ +module MisspelledFlagA where diff --git a/testsuite/tests/driver/should_fail/T11789a.stderr b/testsuite/tests/driver/should_fail/T11789a.stderr new file mode 100644 index 0000000000..3e2b780e06 --- /dev/null +++ b/testsuite/tests/driver/should_fail/T11789a.stderr @@ -0,0 +1,5 @@ +ghc: unrecognised flag: -fppr-cols=1000 +did you mean one of: + -dppr-cols + +Usage: For basic information, try the `--help' option. diff --git a/testsuite/tests/driver/should_fail/T11789b.hs b/testsuite/tests/driver/should_fail/T11789b.hs new file mode 100644 index 0000000000..87ac7b8a39 --- /dev/null +++ b/testsuite/tests/driver/should_fail/T11789b.hs @@ -0,0 +1 @@ +module MisspelledFlagB where diff --git a/testsuite/tests/driver/should_fail/T11789b.stderr b/testsuite/tests/driver/should_fail/T11789b.stderr new file mode 100644 index 0000000000..4c4e0c63c4 --- /dev/null +++ b/testsuite/tests/driver/should_fail/T11789b.stderr @@ -0,0 +1,7 @@ +ghc: unrecognised flag: -rtsopts=somw +did you mean one of: + -rtsopts=some + -rtsopts=none + -rtsopts + +Usage: For basic information, try the `--help' option. diff --git a/testsuite/tests/driver/should_fail/all.T b/testsuite/tests/driver/should_fail/all.T index 3d0708b285..22c8375cfc 100644 --- a/testsuite/tests/driver/should_fail/all.T +++ b/testsuite/tests/driver/should_fail/all.T @@ -2,3 +2,6 @@ test('T10895', normal, multimod_compile_fail, ['T10895.hs', '-v0 -o dummy']) test('T12752', expect_fail, compile, ['-Wcpp-undef -Werror']) + +test('T11789a', normal, compile_fail, ['-fppr-cols=1000']) +test('T11789b', normal, compile_fail, ['-rtsopts=somw']) |