Commit a5e9da8f authored by Ömer Sinan Ağacan's avatar Ömer Sinan Ağacan Committed by Ben Gamari
Browse files

Fix off-by-one error in GHCi line reporting (Trac #10578)

Test Plan: I couldn't add tests because apparently line number
reporting was already working correctly when loading script files. I
don't know how to test by running commands using stdin, is this
supported?

Reviewers: austin, thomie, bgamari

Reviewed By: thomie, bgamari

Subscribers: hvr, thomie

Differential Revision: https://phabricator.haskell.org/D1067
parent 2c9de9c9
...@@ -424,7 +424,10 @@ interactiveUI config srcs maybe_exprs = do ...@@ -424,7 +424,10 @@ interactiveUI config srcs maybe_exprs = do
stop = default_stop, stop = default_stop,
editor = default_editor, editor = default_editor,
options = [], options = [],
line_number = 1, -- We initialize line number as 0, not 1, because we use
-- current line number while reporting errors which is
-- incremented after reading a line.
line_number = 0,
break_ctr = 0, break_ctr = 0,
breaks = [], breaks = [],
tickarrays = emptyModuleEnv, tickarrays = emptyModuleEnv,
...@@ -536,7 +539,7 @@ runGHCi paths maybe_exprs = do ...@@ -536,7 +539,7 @@ runGHCi paths maybe_exprs = do
let show_prompt = verbosity dflags > 0 || is_tty let show_prompt = verbosity dflags > 0 || is_tty
-- reset line number -- reset line number
modifyGHCiState $ \st -> st{line_number=1} modifyGHCiState $ \st -> st{line_number=0}
case maybe_exprs of case maybe_exprs of
Nothing -> Nothing ->
...@@ -745,7 +748,7 @@ runCommands' eh sourceErrorHandler gCmd = gmask $ \unmask -> do ...@@ -745,7 +748,7 @@ runCommands' eh sourceErrorHandler gCmd = gmask $ \unmask -> do
case b of case b of
Nothing -> return Nothing Nothing -> return Nothing
Just success -> do Just success -> do
when (not success) $ maybe (return ()) lift sourceErrorHandler unless success $ maybe (return ()) lift sourceErrorHandler
unmask $ runCommands' eh sourceErrorHandler gCmd unmask $ runCommands' eh sourceErrorHandler gCmd
-- | Evaluate a single line of user input (either :<command> or Haskell code). -- | Evaluate a single line of user input (either :<command> or Haskell code).
......
<interactive>:5:1: error: <interactive>:4:1: error:
No instance for (Show (t -> t1)) arising from a use of ‘print’ No instance for (Show (t -> t1)) arising from a use of ‘print’
(maybe you haven't applied a function to enough arguments?) (maybe you haven't applied a function to enough arguments?)
In a stmt of an interactive GHCi command: print it In a stmt of an interactive GHCi command: print it
<interactive>:6:1: <interactive>:5:1:
No instance for (Show t1) arising from a use of ‘print’ No instance for (Show t1) arising from a use of ‘print’
Cannot resolve unknown runtime type ‘t1’ Cannot resolve unknown runtime type ‘t1’
Use :print or :force to determine these types Use :print or :force to determine these types
Relevant bindings include it :: t1 (bound at <interactive>:6:1) Relevant bindings include it :: t1 (bound at <interactive>:5:1)
Note: there are several potential instances: Note: there are several potential instances:
instance (Show a, Show b) => Show (Either a b) instance (Show a, Show b) => Show (Either a b)
-- Defined in ‘Data.Either’ -- Defined in ‘Data.Either’
...@@ -15,11 +15,11 @@ ...@@ -15,11 +15,11 @@
...plus 33 others ...plus 33 others
In a stmt of an interactive GHCi command: print it In a stmt of an interactive GHCi command: print it
<interactive>:8:1: <interactive>:7:1:
No instance for (Show t1) arising from a use of ‘print’ No instance for (Show t1) arising from a use of ‘print’
Cannot resolve unknown runtime type ‘t1’ Cannot resolve unknown runtime type ‘t1’
Use :print or :force to determine these types Use :print or :force to determine these types
Relevant bindings include it :: t1 (bound at <interactive>:8:1) Relevant bindings include it :: t1 (bound at <interactive>:7:1)
Note: there are several potential instances: Note: there are several potential instances:
instance (Show a, Show b) => Show (Either a b) instance (Show a, Show b) => Show (Either a b)
-- Defined in ‘Data.Either’ -- Defined in ‘Data.Either’
......
<interactive>:11:1: <interactive>:10:1:
No instance for (Show a1) arising from a use of ‘print’ No instance for (Show a1) arising from a use of ‘print’
Cannot resolve unknown runtime type ‘a1’ Cannot resolve unknown runtime type ‘a1’
Use :print or :force to determine these types Use :print or :force to determine these types
Relevant bindings include it :: a1 (bound at <interactive>:11:1) Relevant bindings include it :: a1 (bound at <interactive>:10:1)
Note: there are several potential instances: Note: there are several potential instances:
instance Show TyCon -- Defined in ‘Data.Typeable.Internal’ instance Show TyCon -- Defined in ‘Data.Typeable.Internal’
instance Show TypeRep -- Defined in ‘Data.Typeable.Internal’ instance Show TypeRep -- Defined in ‘Data.Typeable.Internal’
......
A.hs:1:16: error: parse error on input ‘where’ A.hs:1:16: error: parse error on input ‘where’
<interactive>:26:1: error: <interactive>:25:1: error:
Variable not in scope: yan Variable not in scope: yan
Perhaps you meant ‘tan’ (imported from Prelude) Perhaps you meant ‘tan’ (imported from Prelude)
......
...@@ -8,7 +8,7 @@ Bad.hs:3:8: error: ...@@ -8,7 +8,7 @@ Bad.hs:3:8: error:
Bad.hs:3:8: error: Bad.hs:3:8: error:
lexical error in string/character literal at character '\n' lexical error in string/character literal at character '\n'
<interactive>:10:1: error: parse error on input ‘+’ <interactive>:9:1: error: parse error on input ‘+’
Bad.hs:3:8: error: Bad.hs:3:8: error:
lexical error in string/character literal at character '\n' lexical error in string/character literal at character '\n'
......
...@@ -128,7 +128,7 @@ ...@@ -128,7 +128,7 @@
In an equation for ‘b’: b x = x == x In an equation for ‘b’: b x = x == x
(deferred type error) (deferred type error)
<interactive>:8:11: error: <interactive>:7:11: error:
Couldn't match type ‘Bool’ with ‘Int’ Couldn't match type ‘Bool’ with ‘Int’
Expected type: C Int Expected type: C Int
Actual type: C Bool Actual type: C Bool
...@@ -175,7 +175,7 @@ ...@@ -175,7 +175,7 @@
In an equation for ‘j’: j = myOp 23 In an equation for ‘j’: j = myOp 23
(deferred type error) (deferred type error)
<interactive>:14:8: error: <interactive>:13:8: error:
Couldn't match expected type ‘Bool’ with actual type ‘Int’ Couldn't match expected type ‘Bool’ with actual type ‘Int’
In the first argument of ‘print’, namely ‘(k 2)’ In the first argument of ‘print’, namely ‘(k 2)’
In the expression: print (k 2) In the expression: print (k 2)
......
<interactive>:3:10: warning: <interactive>:2:10: warning:
Found hole: _ :: IO () Found hole: _ :: IO ()
In the second argument of ‘(<$>)’, namely ‘_’ In the second argument of ‘(<$>)’, namely ‘_’
In the first argument of ‘ghciStepIO :: IO a -> IO a’, namely In the first argument of ‘ghciStepIO :: IO a -> IO a’, namely
‘Just <$> _’ ‘Just <$> _’
In a stmt of an interactive GHCi command: In a stmt of an interactive GHCi command:
it <- ghciStepIO :: IO a -> IO a (Just <$> _) it <- ghciStepIO :: IO a -> IO a (Just <$> _)
*** Exception: <interactive>:3:10: error: *** Exception: <interactive>:2:10: error:
Found hole: _ :: IO () Found hole: _ :: IO ()
In the second argument of ‘(<$>)’, namely ‘_’ In the second argument of ‘(<$>)’, namely ‘_’
In the first argument of ‘ghciStepIO :: IO a -> IO a’, namely In the first argument of ‘ghciStepIO :: IO a -> IO a’, namely
......
<interactive>:3:1: error: <interactive>:2:1: error:
No instance for (Show (t0 -> t0)) arising from a use of ‘print’ No instance for (Show (t0 -> t0)) arising from a use of ‘print’
(maybe you haven't applied a function to enough arguments?) (maybe you haven't applied a function to enough arguments?)
In a stmt of an interactive GHCi command: print it In a stmt of an interactive GHCi command: print it
<interactive>:11:1: error: <interactive>:10:1: error:
No instance for (Show (t0 -> t0)) arising from a use of ‘print’ No instance for (Show (t0 -> t0)) arising from a use of ‘print’
(maybe you haven't applied a function to enough arguments?) (maybe you haven't applied a function to enough arguments?)
In a stmt of an interactive GHCi command: print it In a stmt of an interactive GHCi command: print it
<interactive>:20:1: error: <interactive>:19:1: error:
No instance for (Show (t0 -> t0)) arising from a use of ‘print’ No instance for (Show (t0 -> t0)) arising from a use of ‘print’
(maybe you haven't applied a function to enough arguments?) (maybe you haven't applied a function to enough arguments?)
In a stmt of an interactive GHCi command: print it In a stmt of an interactive GHCi command: print it
<interactive>:29:1: error: <interactive>:28:1: error:
No instance for (Show (t0 -> t0)) arising from a use of ‘print’ No instance for (Show (t0 -> t0)) arising from a use of ‘print’
(maybe you haven't applied a function to enough arguments?) (maybe you haven't applied a function to enough arguments?)
In a stmt of an interactive GHCi command: print it In a stmt of an interactive GHCi command: print it
<interactive>:50:1: error: <interactive>:49:1: error:
No instance for (Show (t0 -> t0)) arising from a use of ‘print’ No instance for (Show (t0 -> t0)) arising from a use of ‘print’
(maybe you haven't applied a function to enough arguments?) (maybe you haven't applied a function to enough arguments?)
In a stmt of an interactive GHCi command: print it In a stmt of an interactive GHCi command: print it
<interactive>:8:1: <interactive>:7:1:
No instance for (Show Float) arising from a use of ‘print’ No instance for (Show Float) arising from a use of ‘print’
In a stmt of an interactive GHCi command: print it In a stmt of an interactive GHCi command: print it
<interactive>:16:1: <interactive>:15:1:
No instance for (Show Float) arising from a use of ‘print’ No instance for (Show Float) arising from a use of ‘print’
In a stmt of an interactive GHCi command: print it In a stmt of an interactive GHCi command: print it
<interactive>:2:1: error: Variable not in scope: α <interactive>:1:1: error: Variable not in scope: α
<interactive>:3:68: <interactive>:2:68:
Multiple declarations of ‘f’ Multiple declarations of ‘f’
Declared at: <interactive>:3:32 Declared at: <interactive>:2:32
<interactive>:3:68 <interactive>:2:68
In the Template Haskell quotation In the Template Haskell quotation
[d| f = undefined [d| f = undefined
class Foo x where class Foo x where
......
<interactive>:3:1: error: <interactive>:2:1: error:
Variable not in scope: git Variable not in scope: git
Perhaps you meant ‘it’ (line 2) Perhaps you meant ‘it’ (line 1)
<interactive>:5:1: error: <interactive>:4:1: error:
Variable not in scope: fit Variable not in scope: fit
Perhaps you meant one of these: Perhaps you meant one of these:
‘fst’ (imported from Prelude), ‘Ghci1.it’ (imported from Ghci1), ‘fst’ (imported from Prelude), ‘Ghci1.it’ (imported from Ghci1),
‘it’ (line 4) ‘it’ (line 3)
data (?) -- Defined at <interactive>:3:1 data (?) -- Defined at <interactive>:2:1
type role A phantom phantom type role A phantom phantom
data A (x :: k) (y :: k1) data A (x :: k) (y :: k1)
-- Defined at <interactive>:3:1 -- Defined at <interactive>:2:1
A :: k -> k1 -> * A :: k -> k1 -> *
type role T phantom type role T phantom
data T (a :: k) where data T (a :: k) where
MkT :: forall (k :: BOX) (a :: k) a1. a1 -> T a MkT :: forall (k :: BOX) (a :: k) a1. a1 -> T a
-- Defined at <interactive>:7:1 -- Defined at <interactive>:6:1
type T = forall a. a -> a -- Defined at <interactive>:3:1 type T = forall a. a -> a -- Defined at <interactive>:2:1
data D = MkT (forall b. b -> b) -- Defined at <interactive>:4:1 data D = MkT (forall b. b -> b) -- Defined at <interactive>:3:1
data D1 where data D1 where
MkD1 :: (forall (k1 :: BOX) (p :: k1 -> *) (a :: k1). p a -> Int) MkD1 :: (forall (k1 :: BOX) (p :: k1 -> *) (a :: k1). p a -> Int)
-> D1 -> D1
-- Defined at <interactive>:3:1 -- Defined at <interactive>:2:1
data D2 where data D2 where
MkD2 :: (forall (p :: k -> *) (a :: k). p a -> Int) -> D2 MkD2 :: (forall (p :: k -> *) (a :: k). p a -> Int) -> D2
-- Defined at <interactive>:4:1 -- Defined at <interactive>:3:1
<interactive>:3:11: error: <interactive>:2:11: error:
The role annotation for ‘X’ lacks an accompanying binding The role annotation for ‘X’ lacks an accompanying binding
(The role annotation must be given where ‘X’ is declared) (The role annotation must be given where ‘X’ is declared)
data A = Y -- Defined at <interactive>:3:1 data A = Y -- Defined at <interactive>:2:1
data A = Y -- Defined at <interactive>:3:1 data A = Y -- Defined at <interactive>:2:1
<interactive>:5:4: error: <interactive>:4:4: error:
Couldn't match expected type ‘Ghci1.X’ Couldn't match expected type ‘Ghci1.X’
with actual type ‘X’ with actual type ‘X’
NB: ‘X’ is defined at <interactive>:4:1-25 NB: ‘X’ is defined at <interactive>:3:1-25
‘Ghci1.X’ is defined at <interactive>:2:1-14 ‘Ghci1.X’ is defined at <interactive>:1:1-14
In the first argument of ‘f’, namely ‘(Y 3)’ In the first argument of ‘f’, namely ‘(Y 3)’
In the expression: f (Y 3) In the expression: f (Y 3)
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