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

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
stop = default_stop,
editor = default_editor,
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,
breaks = [],
tickarrays = emptyModuleEnv,
......@@ -536,7 +539,7 @@ runGHCi paths maybe_exprs = do
let show_prompt = verbosity dflags > 0 || is_tty
-- reset line number
modifyGHCiState $ \st -> st{line_number=1}
modifyGHCiState $ \st -> st{line_number=0}
case maybe_exprs of
Nothing ->
......@@ -745,7 +748,7 @@ runCommands' eh sourceErrorHandler gCmd = gmask $ \unmask -> do
case b of
Nothing -> return Nothing
Just success -> do
when (not success) $ maybe (return ()) lift sourceErrorHandler
unless success $ maybe (return ()) lift sourceErrorHandler
unmask $ runCommands' eh sourceErrorHandler gCmd
-- | 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’
(maybe you haven't applied a function to enough arguments?)
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’
Cannot resolve unknown runtime type ‘t1’
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:
instance (Show a, Show b) => Show (Either a b)
-- Defined in ‘Data.Either’
......@@ -15,11 +15,11 @@
...plus 33 others
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’
Cannot resolve unknown runtime type ‘t1’
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:
instance (Show a, Show b) => Show (Either a b)
-- Defined in ‘Data.Either’
......
<interactive>:11:1:
<interactive>:10:1:
No instance for (Show a1) arising from a use of ‘print’
Cannot resolve unknown runtime type ‘a1’
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:
instance Show TyCon -- Defined in ‘Data.Typeable.Internal’
instance Show TypeRep -- Defined in ‘Data.Typeable.Internal’
......
A.hs:1:16: error: parse error on input ‘where’
<interactive>:26:1: error:
<interactive>:25:1: error:
Variable not in scope: yan
Perhaps you meant ‘tan’ (imported from Prelude)
......
......@@ -8,7 +8,7 @@ Bad.hs:3:8: error:
Bad.hs:3:8: error:
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:
lexical error in string/character literal at character '\n'
......
......@@ -128,7 +128,7 @@
In an equation for ‘b’: b x = x == x
(deferred type error)
<interactive>:8:11: error:
<interactive>:7:11: error:
Couldn't match type ‘Bool’ with ‘Int’
Expected type: C Int
Actual type: C Bool
......@@ -175,7 +175,7 @@
In an equation for ‘j’: j = myOp 23
(deferred type error)
<interactive>:14:8: error:
<interactive>:13:8: error:
Couldn't match expected type ‘Bool’ with actual type ‘Int’
In the first argument of ‘print’, namely ‘(k 2)’
In the expression: print (k 2)
......
<interactive>:3:10: warning:
<interactive>:2:10: warning:
Found hole: _ :: IO ()
In the second argument of ‘(<$>)’, namely ‘_’
In the first argument of ‘ghciStepIO :: IO a -> IO a’, namely
‘Just <$> _’
In a stmt of an interactive GHCi command:
it <- ghciStepIO :: IO a -> IO a (Just <$> _)
*** Exception: <interactive>:3:10: error:
*** Exception: <interactive>:2:10: error:
Found hole: _ :: IO ()
In the second argument of ‘(<$>)’, 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’
(maybe you haven't applied a function to enough arguments?)
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’
(maybe you haven't applied a function to enough arguments?)
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’
(maybe you haven't applied a function to enough arguments?)
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’
(maybe you haven't applied a function to enough arguments?)
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’
(maybe you haven't applied a function to enough arguments?)
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’
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’
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’
Declared at: <interactive>:3:32
<interactive>:3:68
Declared at: <interactive>:2:32
<interactive>:2:68
In the Template Haskell quotation
[d| f = undefined
class Foo x where
......
<interactive>:3:1: error:
<interactive>:2:1: error:
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
Perhaps you meant one of these:
‘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
data A (x :: k) (y :: k1)
-- Defined at <interactive>:3:1
-- Defined at <interactive>:2:1
A :: k -> k1 -> *
type role T phantom
data T (a :: k) where
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
data D = MkT (forall b. b -> b) -- Defined at <interactive>:4:1
type T = forall a. a -> a -- Defined at <interactive>:2:1
data D = MkT (forall b. b -> b) -- Defined at <interactive>:3:1
data D1 where
MkD1 :: (forall (k1 :: BOX) (p :: k1 -> *) (a :: k1). p a -> Int)
-> D1
-- Defined at <interactive>:3:1
-- Defined at <interactive>:2:1
data D2 where
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 must be given where ‘X’ is declared)
data A = Y -- Defined at <interactive>:3:1
data A = Y -- Defined at <interactive>:3:1
data A = Y -- Defined at <interactive>:2:1
data A = Y -- Defined at <interactive>:2:1
<interactive>:5:4: error:
<interactive>:4:4: error:
Couldn't match expected type ‘Ghci1.X’
with actual type ‘X’
NB: ‘X’ is defined at <interactive>:4:1-25
‘Ghci1.X’ is defined at <interactive>:2:1-14
NB: ‘X’ is defined at <interactive>:3:1-25
‘Ghci1.X’ is defined at <interactive>:1:1-14
In the first argument of ‘f’, namely ‘(Y 3)’
In the expression: f (Y 3)
......@@ -3,7 +3,7 @@
Arrow command found where an expression was expected:
() >- () -< () >>- () -<< ()
<interactive>:7:15:
<interactive>:6:15:
Couldn't match expected type ‘()’ with actual type ‘Bool’
In the pattern: True
In a stmt of a pattern guard for
......@@ -15,7 +15,7 @@
Arrow command found where an expression was expected:
() ↣ () ↢ () ⤜ () ⤛ ()
<interactive>:14:15:
<interactive>:13:15:
Couldn't match expected type ‘()’ with actual type ‘Bool’
In the pattern: True
In a stmt of a pattern guard for
......@@ -27,7 +27,7 @@
Arrow command found where an expression was expected:
() >- () -< () >>- () -<< ()
<interactive>:21:15:
<interactive>:20:15:
Couldn't match expected type ‘()’ with actual type ‘Bool’
In the pattern: True
In a stmt of a pattern guard for
......
<interactive>:3:5:
<interactive>:2:5:
You can't mix polymorphic and unlifted bindings
a = (# 1 #)
Probable fix: use a bang pattern
<interactive>:4:5:
<interactive>:3:5:
You can't mix polymorphic and unlifted bindings
a = (# 1, 3 #)
Probable fix: use a bang pattern
......
<interactive>:5:1: error:
<interactive>:4:1: error:
Illegal generalised algebraic data declaration for ‘T’
(Use GADTs to allow GADTs)
In the data declaration for ‘T’
......
($$$) :: [a -> c] -> [a] -> [c] -- Defined at <interactive>:2:8
($$$) :: [a -> c] -> [a] -> [c] -- Defined at <interactive>:1:8
data Ghci1.T = A | ... -- Defined at <interactive>:3:10
data Ghci1.T = A | ... -- Defined at <interactive>:2:10
data R = A | ... -- Defined at <interactive>:4:10
data R = A | ... -- Defined at <interactive>:3:10
data T = A {...} -- Defined at <interactive>:3:10
data T = A {a :: Int} -- Defined at <interactive>:3:13
a :: Integer -- Defined at <interactive>:6:5
data T = A {...} -- Defined at <interactive>:2:10
data T = A {a :: Int} -- Defined at <interactive>:2:13
a :: Integer -- Defined at <interactive>:5:5
3
data R = B {a :: Int} -- Defined at <interactive>:9:13
data T = A {Ghci1.a :: Int} -- Defined at <interactive>:3:1
data R = B {a :: Int} -- Defined at <interactive>:8:13
data T = A {Ghci1.a :: Int} -- Defined at <interactive>:2:1
<interactive>:10:1: error:
<interactive>:9:1: error:
Overlapping instances for C [Int] arising from a use of ‘f’
Matching instances:
instance [safe] C [Int] -- Defined at <interactive>:7:10
instance [safe] C a => C [a] -- Defined at <interactive>:9:10
instance [safe] C [Int] -- Defined at <interactive>:6:10
instance [safe] C a => C [a] -- Defined at <interactive>:8:10
In the expression: f [4 :: Int]
In an equation for ‘it’: it = f [4 :: Int]
<interactive>:39:1:
<interactive>:38:1:
Couldn't match type ‘HFalse’ with ‘HTrue’
Expected type: HTrue
Actual type: Or HFalse HFalse
......@@ -7,7 +7,7 @@
In the expression: f $ Baz 'a'
In an equation for ‘it’: it = f $ Baz 'a'
<interactive>:40:1:
<interactive>:39:1:
Couldn't match type ‘HFalse’ with ‘HTrue’
Expected type: HTrue
Actual type: Or HFalse HFalse
......
<interactive>:4:16:
<interactive>:3:16:
Multiple declarations of ‘A’
Declared at: <interactive>:4:12
<interactive>:4:16
Declared at: <interactive>:3:12
<interactive>:3:16
<interactive>:6:16:
<interactive>:5:16:
Multiple declarations of ‘A’
Declared at: <interactive>:6:12
<interactive>:6:16
Declared at: <interactive>:5:12
<interactive>:5:16
<interactive>:6:49: error:
<interactive>:5:49: error:
Couldn't match expected type ‘ListableElem (a, a)’
with actual type ‘a’
‘a’ is a rigid type variable bound by
the instance declaration at <interactive>:6:10
the instance declaration at <interactive>:5:10
Relevant bindings include
b :: a (bound at <interactive>:6:43)
a :: a (bound at <interactive>:6:41)
b :: a (bound at <interactive>:5:43)
a :: a (bound at <interactive>:5:41)
asList :: (a, a) -> [ListableElem (a, a)]
(bound at <interactive>:6:33)
(bound at <interactive>:5:33)
In the expression: a
In the expression: [a, b]
<interactive>:7:9: error:
<interactive>:6:9: error:
Couldn't match type ‘T’
with ‘Ghci1.T’
NB: ‘Ghci1.T’ is defined at <interactive>:3:1-14
‘T’ is defined at <interactive>:6:1-16
NB: ‘Ghci1.T’ is defined at <interactive>:2:1-14
‘T’ is defined at <interactive>:5:1-16
Expected type: T'
Actual type: T
In the expression: C :: T'
......
data T = C | D -- Defined at <interactive>:9:1
type T' = Ghci1.T -- Defined at <interactive>:4:1
data Ghci1.T = A | ... -- Defined at <interactive>:3:10
data Ghci4.T = B | ... -- Defined at <interactive>:6:12
data T = C | ... -- Defined at <interactive>:9:14
data T = ... | D -- Defined at <interactive>:9:18
b :: T' -- Defined at <interactive>:5:5
c :: Ghci4.T -- Defined at <interactive>:8:5
d :: T -- Defined at <interactive>:10:5
data T = C | D -- Defined at <interactive>:8:1
type T' = Ghci1.T -- Defined at <interactive>:3:1
data Ghci1.T = A | ... -- Defined at <interactive>:2:10
data Ghci4.T = B | ... -- Defined at <interactive>:5:12
data T = C | ... -- Defined at <interactive>:8:14
data T = ... | D -- Defined at <interactive>:8:18
b :: T' -- Defined at <interactive>:4:5
c :: Ghci4.T -- Defined at <interactive>:7:5
d :: T -- Defined at <interactive>:9:5
<interactive>:9:4: error:
<interactive>:8:4: error:
Couldn't match expected type ‘Ghci1.Planet’
with actual type ‘Planet’
NB: ‘Planet’ is defined at <interactive>:8:1-36
‘Ghci1.Planet’ is defined at <interactive>:5:1-37
NB: ‘Planet’ is defined at <interactive>:7:1-36
‘Ghci1.Planet’ is defined at <interactive>:4:1-37
In the first argument of ‘pn’, namely ‘Mercury’
In the expression: pn Mercury
<interactive>:10:4: error:
<interactive>:9:4: error:
Couldn't match expected type ‘Ghci1.Planet’
with actual type ‘Planet’
NB: ‘Planet’ is defined at <interactive>:8:1-36
‘Ghci1.Planet’ is defined at <interactive>:5:1-37
NB: ‘Planet’ is defined at <interactive>:7:1-36
‘Ghci1.Planet’ is defined at <interactive>:4:1-37
In the first argument of ‘pn’, namely ‘Venus’
In the expression: pn Venus
<interactive>:11:4: error:
<interactive>:10:4: error:
Couldn't match expected type ‘Ghci1.Planet’
with actual type ‘Planet’
NB: ‘Planet’ is defined at <interactive>:8:1-36
‘Ghci1.Planet’ is defined at <interactive>:5:1-37
NB: ‘Planet’ is defined at <interactive>:7:1-36
‘Ghci1.Planet’ is defined at <interactive>:4:1-37
In the first argument of ‘pn’, namely ‘Mars’
In the expression: pn Mars
<interactive>:13:44: error:
<interactive>:12:44: error:
Couldn't match expected type ‘Planet’
with actual type ‘Ghci1.Planet’
NB: ‘Ghci1.Planet’ is defined at <interactive>:5:1-37
‘Planet’ is defined at <interactive>:8:1-36
NB: ‘Ghci1.Planet’ is defined at <interactive>:4:1-37
‘Planet’ is defined at <interactive>:7:1-36
In the pattern: Earth
In an equation for ‘pn’: pn Earth = "E"
<interactive>:10:12: error:
<interactive>:9:12: error:
Couldn't match expected type ‘Ghci1.Planet’
with actual type ‘Planet’
NB: ‘Planet’ is defined at <interactive>:8:1-41
‘Ghci1.Planet’ is defined at <interactive>:5:1-49
NB: ‘Planet’ is defined at <interactive>:7:1-41
‘Ghci1.Planet’ is defined at <interactive>:4:1-49
In the second argument of ‘(==)’, namely ‘Mercury’
In the expression: mercury == Mercury
<interactive>:12:10: error:
<interactive>:11:10: error:
Couldn't match expected type ‘Planet’
with actual type ‘Ghci1.Planet’
NB: ‘Ghci1.Planet’ is defined at <interactive>:5:1-49
‘Planet’ is defined at <interactive>:8:1-41
NB: ‘Ghci1.Planet’ is defined at <interactive>:4:1-49
‘Planet’ is defined at <interactive>:7:1-41
In the second argument of ‘(==)’, namely ‘Earth’
In the expression: Venus == Earth
<interactive>:5:1: error:
<interactive>:4:1: error:
Illegal generalised algebraic data declaration for ‘T’
(Use GADTs to allow GADTs)
In the data declaration for ‘T’
......
1
2
2
data T1 = MkT1 -- Defined at <interactive>:7:1
data T2 = MkT2 -- Defined at <interactive>:9:2
data T1 = MkT1 -- Defined at <interactive>:6:1
data T2 = MkT2 -- Defined at <interactive>:8:2
<interactive>:3:9: error:
<interactive>:2:9: error:
parse error on input ‘=’
Perhaps you need a 'let' in a 'do' block?
e.g. 'let x = 5' instead of 'x = 5'
*** Exception: <interactive>:6:5-35: Non-exhaustive patterns in function foo
*** Exception: <interactive>:5:5-35: Non-exhaustive patterns in function foo
pattern Single :: t -> [t] -- Defined at <interactive>:4:1
pattern Single :: t -> [t] -- Defined at <interactive>:3:1
foo :: [Bool] -> [Bool]
[False]
<interactive>:10:1: error: Variable not in scope: b
<interactive>:9:1: error: Variable not in scope: b
<interactive>:11:1: error:
<interactive>:10:1: error:
Unsafe overlapping instances for Pos [Int]
arising from a use of ‘res’
The matching instance is:
instance [overlapping] [safe] Pos [Int]
-- Defined at <interactive>:9:30
-- Defined at <interactive>:8:30
It is compiled in a Safe module and as such can only
overlap instances from the same module, however it
overlaps the following instances from different modules:
......
<interactive>:10:1: parse error on input ‘{-# RULES’
<interactive>:9:1: parse error on input ‘{-# RULES’
......@@ -2,14 +2,14 @@
<no location info>: warning:
-XGeneralizedNewtypeDeriving is not allowed in Safe Haskell; ignoring -XGeneralizedNewtypeDeriving
<interactive>:16:29: error:
<interactive>:15:29: error:
Can't make a derived instance of ‘Op T2’:
‘Op’ is not a derivable class
Try GeneralizedNewtypeDeriving for GHC's newtype-deriving extension
In the newtype declaration for ‘T2’
<interactive>:19:9: error:
<interactive>:18:9: error:
Data constructor not in scope: T2 :: T -> t
Perhaps you meant ‘T1’ (line 13)
Perhaps you meant ‘T1’ (line 12)
<interactive>:22:4: error: Variable not in scope: y
<interactive>:21:4: error: Variable not in scope: y
<interactive>:6:9: error:
<interactive>:5:9: error:
Not in scope: ‘System.IO.Unsafe.unsafePerformIO’
<interactive>:7:9: error:
<interactive>:6:9: error:
Variable not in scope: x :: IO Integer -> t
<interactive>:8:1: error: Variable not in scope: y
<interactive>:7:1: error: Variable not in scope: y
<interactive>:12:1: error:
<interactive>:11:1: error:
Unacceptable result type in foreign declaration:
Safe Haskell is on, all FFI imports must be in the IO monad
When checking declaration:
foreign import ccall safe "static sin" c_sin :: Double -> Double
<interactive>:13:1: error:
<interactive>:12:1: error:
Variable not in scope: c_sin :: Integer -> t
Perhaps you meant ‘c_sin'’ (line 8)
Perhaps you meant ‘c_sin'’ (line 7)
<interactive>:10:1: error: Variable not in scope: b
<interactive>:9:1: error: Variable not in scope: b