[commit: ghc] master: Strip leading whitespace before checking if a statement looks like a declaration (fixes #9914) (707fb3a)

git at git.haskell.org git at git.haskell.org
Mon Dec 22 11:04:34 UTC 2014


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/707fb3aa2b058cb4245708d6a63019b3e32f795c/ghc

>---------------------------------------------------------------

commit 707fb3aa2b058cb4245708d6a63019b3e32f795c
Author: Dr. ERDI Gergo <gergo at erdi.hu>
Date:   Mon Dec 22 19:01:37 2014 +0800

    Strip leading whitespace before checking if a statement looks like a declaration (fixes #9914)


>---------------------------------------------------------------

707fb3aa2b058cb4245708d6a63019b3e32f795c
 ghc/InteractiveUI.hs                         | 6 ++++--
 testsuite/tests/ghci/should_run/T9914.script | 9 +++++++++
 testsuite/tests/ghci/should_run/T9914.stdout | 5 +++++
 testsuite/tests/ghci/should_run/all.T        | 1 +
 4 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/ghc/InteractiveUI.hs b/ghc/InteractiveUI.hs
index 4a296da..7d6c9ba 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 0000000..d40f46f
--- /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 0000000..3dd5aff
--- /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 effad6a..b28e4a3 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'])



More information about the ghc-commits mailing list