Commit 181688ab authored by Daishi Nakajima's avatar Daishi Nakajima Committed by Ben Gamari
Browse files

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
parent 852c6a09
......@@ -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]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......
ghc: unrecognised flag: -fppr-cols=1000
did you mean one of:
-dppr-cols
Usage: For basic information, try the `--help' option.
ghc: unrecognised flag: -rtsopts=somw
did you mean one of:
-rtsopts=some
-rtsopts=none
-rtsopts
Usage: For basic information, try the `--help' option.
......@@ -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'])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment