[commit: ghc] master: Improve suggestion for misspelled flag including '=' (fixes #11789) (181688a)
git at git.haskell.org
git at git.haskell.org
Wed Jan 18 22:40:03 UTC 2017
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/181688abae5c0b32237a5bd783dfc9667641cce2/ghc
>---------------------------------------------------------------
commit 181688abae5c0b32237a5bd783dfc9667641cce2
Author: Daishi Nakajima <nakaji.dayo at gmail.com>
Date: Wed Jan 18 16:23:55 2017 -0500
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
>---------------------------------------------------------------
181688abae5c0b32237a5bd783dfc9667641cce2
ghc/Main.hs | 11 ++++++++++-
testsuite/tests/driver/should_fail/T11789a.hs | 1 +
testsuite/tests/driver/should_fail/T11789a.stderr | 5 +++++
testsuite/tests/driver/should_fail/T11789b.hs | 1 +
testsuite/tests/driver/should_fail/T11789b.stderr | 7 +++++++
testsuite/tests/driver/should_fail/all.T | 3 +++
6 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/ghc/Main.hs b/ghc/Main.hs
index 83d5238..a650d35 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 0000000..78595d6
--- /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 0000000..3e2b780
--- /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 0000000..87ac7b8
--- /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 0000000..4c4e0c6
--- /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 3d0708b..22c8375 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'])
More information about the ghc-commits
mailing list