Commit 707fb3aa authored by Gergő Érdi's avatar Gergő Érdi
Browse files

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

parent 6713f0d9
......@@ -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
......
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
1
2
2
data T1 = MkT1 -- Defined at <interactive>:7:1
data T2 = MkT2 -- Defined at <interactive>:9:2
......@@ -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'])
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