Improve suggestion for misspelled flag including '=' (fixes #11789)
authorDaishi Nakajima <nakaji.dayo@gmail.com>
Wed, 18 Jan 2017 21:23:55 +0000 (16:23 -0500)
committerBen Gamari <ben@smart-cactus.org>
Wed, 18 Jan 2017 22:39:48 +0000 (17:39 -0500)
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

ghc/Main.hs
testsuite/tests/driver/should_fail/T11789a.hs [new file with mode: 0644]
testsuite/tests/driver/should_fail/T11789a.stderr [new file with mode: 0644]
testsuite/tests/driver/should_fail/T11789b.hs [new file with mode: 0644]
testsuite/tests/driver/should_fail/T11789b.stderr [new file with mode: 0644]
testsuite/tests/driver/should_fail/all.T

index 83d5238..a650d35 100644 (file)
@@ -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 (file)
index 0000000..78595d6
--- /dev/null
@@ -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 (file)
index 0000000..3e2b780
--- /dev/null
@@ -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 (file)
index 0000000..87ac7b8
--- /dev/null
@@ -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 (file)
index 0000000..4c4e0c6
--- /dev/null
@@ -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.
index 3d0708b..22c8375 100644 (file)
@@ -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'])