summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroland <rsx@bluewin.ch>2018-08-06 16:50:38 (GMT)
committerBen Gamari <ben@smart-cactus.org>2018-08-06 21:53:14 (GMT)
commitff06176b87078ce56cc7b6b3405a029ef3d0046f (patch)
treec9c4f42c61e49fef99be899a628a8b8915851133
parent4fc6524a2a4a0003495a96c8b84783286f65c198 (diff)
downloadghc-ff06176b87078ce56cc7b6b3405a029ef3d0046f.zip
ghc-ff06176b87078ce56cc7b6b3405a029ef3d0046f.tar.gz
ghc-ff06176b87078ce56cc7b6b3405a029ef3d0046f.tar.bz2
Improve error message for flags with missing required arguments (#12625)
Test Plan: make TEST=T12625 Reviewers: jstolarek, austin, bgamari Reviewed By: bgamari Subscribers: rwbarton, thomie, carter GHC Trac Issues: #12625 Differential Revision: https://phabricator.haskell.org/D5030
-rw-r--r--compiler/main/CmdLineParser.hs6
-rw-r--r--testsuite/tests/driver/T12625.hs2
-rw-r--r--testsuite/tests/driver/T12625.stderr2
-rw-r--r--testsuite/tests/driver/all.T2
4 files changed, 10 insertions, 2 deletions
diff --git a/compiler/main/CmdLineParser.hs b/compiler/main/CmdLineParser.hs
index 49fbd8f..c876f58 100644
--- a/compiler/main/CmdLineParser.hs
+++ b/compiler/main/CmdLineParser.hs
@@ -242,8 +242,9 @@ processOneArg opt_kind rest arg args
[] -> missingArgErr dash_arg
(L _ arg1:args1) -> Right (f arg1, args1)
+ -- See Trac #12625
Prefix f | notNull rest_no_eq -> Right (f rest_no_eq, args)
- | otherwise -> unknownFlagErr dash_arg
+ | otherwise -> missingArgErr dash_arg
PrefixPred _ f | notNull rest_no_eq -> Right (f rest_no_eq, args)
| otherwise -> unknownFlagErr dash_arg
@@ -281,7 +282,8 @@ arg_ok :: OptKind t -> [Char] -> String -> Bool
arg_ok (NoArg _) rest _ = null rest
arg_ok (HasArg _) _ _ = True
arg_ok (SepArg _) rest _ = null rest
-arg_ok (Prefix _) rest _ = notNull rest
+arg_ok (Prefix _) _ _ = True -- Missing argument checked for in processOneArg t
+ -- to improve error message (Trac #12625)
arg_ok (PrefixPred p _) rest _ = notNull rest && p (dropEq rest)
arg_ok (OptIntSuffix _) _ _ = True
arg_ok (IntSuffix _) _ _ = True
diff --git a/testsuite/tests/driver/T12625.hs b/testsuite/tests/driver/T12625.hs
new file mode 100644
index 0000000..b34b914
--- /dev/null
+++ b/testsuite/tests/driver/T12625.hs
@@ -0,0 +1,2 @@
+main :: IO()
+main = putStrLn "T12625"
diff --git a/testsuite/tests/driver/T12625.stderr b/testsuite/tests/driver/T12625.stderr
new file mode 100644
index 0000000..a171dbd
--- /dev/null
+++ b/testsuite/tests/driver/T12625.stderr
@@ -0,0 +1,2 @@
+ghc: on the commandline: missing argument for flag: -I
+Usage: For basic information, try the `--help' option.
diff --git a/testsuite/tests/driver/all.T b/testsuite/tests/driver/all.T
index 6397598..07dc3bf 100644
--- a/testsuite/tests/driver/all.T
+++ b/testsuite/tests/driver/all.T
@@ -264,6 +264,8 @@ test('T12192', normal, run_command, ['mkdir foo && (cd foo && {compiler} -v0 ../
test('T10923', [], run_command, ['$MAKE -s --no-print-directory T10923'])
+test('T12625', normal, compile_fail, ['-I'])
+
test('T12752pass', normal, compile, ['-DSHOULD_PASS=1 -Wcpp-undef'])
test('T12955', normal, run_command, ['$MAKE -s --no-print-directory T12955'])