Strip leading whitespace before checking if a statement looks like a declaration...
authorDr. ERDI Gergo <gergo@erdi.hu>
Mon, 22 Dec 2014 11:01:37 +0000 (19:01 +0800)
committerDr. ERDI Gergo <gergo@erdi.hu>
Mon, 22 Dec 2014 11:01:37 +0000 (19:01 +0800)
ghc/InteractiveUI.hs
testsuite/tests/ghci/should_run/T9914.script [new file with mode: 0644]
testsuite/tests/ghci/should_run/T9914.stdout [new file with mode: 0644]
testsuite/tests/ghci/should_run/all.T

index 4a296da..7d6c9ba 100644 (file)
@@ -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 (file)
index 0000000..d40f46f
--- /dev/null
@@ -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 (file)
index 0000000..3dd5aff
--- /dev/null
@@ -0,0 +1,5 @@
+1
+2
+2
+data T1 = MkT1         -- Defined at <interactive>:7:1
+data T2 = MkT2         -- Defined at <interactive>:9:2
index effad6a..b28e4a3 100644 (file)
@@ -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'])