summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDr. ERDI Gergo <gergo@erdi.hu>2014-12-22 19:01:37 +0800
committerDr. ERDI Gergo <gergo@erdi.hu>2014-12-22 19:01:37 +0800
commit707fb3aa2b058cb4245708d6a63019b3e32f795c (patch)
tree66c6f8697628a44dd3c547f001f1210824982b93
parent6713f0d9ad4a2d875d8f7b245c1c0ca77ce1617f (diff)
downloadhaskell-707fb3aa2b058cb4245708d6a63019b3e32f795c.tar.gz
Strip leading whitespace before checking if a statement looks like a declaration (fixes #9914)
-rw-r--r--ghc/InteractiveUI.hs6
-rw-r--r--testsuite/tests/ghci/should_run/T9914.script9
-rw-r--r--testsuite/tests/ghci/should_run/T9914.stdout5
-rw-r--r--testsuite/tests/ghci/should_run/all.T1
4 files changed, 19 insertions, 2 deletions
diff --git a/ghc/InteractiveUI.hs b/ghc/InteractiveUI.hs
index 4a296dabd0..7d6c9ba87f 100644
--- a/ghc/InteractiveUI.hs
+++ b/ghc/InteractiveUI.hs
@@ -897,12 +897,12 @@ runStmt stmt step
= return False
-- import
- | "import " `isPrefixOf` stmt
+ | stmt `looks_like` "import "
= do addImportToContext stmt; return False
| otherwise
= do dflags <- getDynFlags
- if any (`isPrefixOf` stmt) (declPrefixes dflags)
+ if any (stmt `looks_like`) (declPrefixes dflags)
then run_decl
else run_stmt
where
@@ -923,6 +923,8 @@ runStmt stmt step
Nothing -> return False
Just result -> afterRunStmt (const True) result
+ s `looks_like` prefix = prefix `isPrefixOf` dropWhile isSpace s
+
-- | Clean up the GHCi environment after a statement has run
afterRunStmt :: (SrcSpan -> Bool) -> GHC.RunResult -> GHCi Bool
afterRunStmt _ (GHC.RunException e) = liftIO $ Exception.throwIO e
diff --git a/testsuite/tests/ghci/should_run/T9914.script b/testsuite/tests/ghci/should_run/T9914.script
new file mode 100644
index 0000000000..d40f46f667
--- /dev/null
+++ b/testsuite/tests/ghci/should_run/T9914.script
@@ -0,0 +1,9 @@
+let x = 1
+x
+ let x = 2 -- Note leading whitespace
+x
+2
+data T1 = MkT1
+:i T1
+ data T2 = MkT2 -- Note leading whitespace
+:i T2
diff --git a/testsuite/tests/ghci/should_run/T9914.stdout b/testsuite/tests/ghci/should_run/T9914.stdout
new file mode 100644
index 0000000000..3dd5aff3f3
--- /dev/null
+++ b/testsuite/tests/ghci/should_run/T9914.stdout
@@ -0,0 +1,5 @@
+1
+2
+2
+data T1 = MkT1 -- Defined at <interactive>:7:1
+data T2 = MkT2 -- Defined at <interactive>:9:2
diff --git a/testsuite/tests/ghci/should_run/all.T b/testsuite/tests/ghci/should_run/all.T
index effad6a725..b28e4a3893 100644
--- a/testsuite/tests/ghci/should_run/all.T
+++ b/testsuite/tests/ghci/should_run/all.T
@@ -20,4 +20,5 @@ test('T3171',
test('ghcirun004', just_ghci, compile_and_run, [''])
test('T8377', just_ghci, compile_and_run, [''])
+test('T9914', just_ghci, ghci_script, ['T9914.script'])
test('T9915', just_ghci, ghci_script, ['T9915.script'])