Opened 2 years ago

Closed 2 years ago

#8051 closed bug (fixed)

GHCi: confusing `:set +m`/`:{` interaction & wrong line-numbers in multi-line input

Reported by: hvr Owned by:
Priority: highest Milestone: 7.8.1
Component: GHCi Version: 7.7
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Revisions:

Description

As mentioned in ticket:8047#comment:1 GHCi exhibits a line-numbering offset bug when multi-line input is evaluated.

Morever, when :set +m is active, :{-entered multi-input may trigger multi-line input continuation, e.g.:

Prelude> :set +m
Prelude> :{
Prelude| let x = ()
Prelude|     y = ()
Prelude| :}
Prelude|     z = ()
Prelude| 
Prelude> 

The attached patch fixes both issues, but does so in an admittedly hacky way...

Attachments (3)

ticket-8051-multi-line-number-fix.patch (2.2 KB) - added by hvr 2 years ago.
ticket-8051-multi-line-number-fix.v2.patch (2.4 KB) - added by hvr 2 years ago.
improved patch for better handling :set +m-style continuations
ticket-8051-multi-line-number-fix.v3.patch (4.1 KB) - added by hvr 2 years ago.
3rd attempt at fixing stuff; as a side-effect, this one also fixes wrong single-line column-indices in error messages

Download all attachments as: .zip

Change History (8)

comment:1 Changed 2 years ago by hvr

Btw, here's a minor fixlet for HEAD, which doesn't honor prompt2 for :set +m multi-line input:

  • ghc/InteractiveUI.hs

    diff --git a/ghc/InteractiveUI.hs b/ghc/InteractiveUI.hs
    index 4bac5ad..7b10b65 100644
    a b checkInputForLayout stmt getStmt = do 
    790790     _other              -> do
    791791       st1 <- lift getGHCiState
    792792       let p = prompt st1
    793        lift $ setGHCiState st1{ prompt = "%s| " }
     793       lift $ setGHCiState st1{ prompt = prompt2 st1 }
    794794       mb_stmt <- ghciHandle (\ex -> case fromException ex of
    795795                            Just UserInterrupt -> return Nothing
    796796                            _ -> case fromException ex of
Version 0, edited 2 years ago by hvr (next)

comment:2 Changed 2 years ago by igloo

  • Status changed from new to patch

Changed 2 years ago by hvr

improved patch for better handling :set +m-style continuations

comment:3 Changed 2 years ago by thoughtpolice

  • Milestone set to 7.8.1
  • Priority changed from normal to highest
  • Version changed from 7.6.3 to 7.7

Herbert, after attempting to merge this patch, it causes two ./validate failures for me:

$ make TEST="ghci023 ghci047"
=====> ghci023(ghci) 2660 of 3765 [0, 0, 0]
cd ./ghci/scripts && HC='/home/a/ghc/ghc-pristine/inplace/bin/ghc-stage2' HC_OPTS='-dcore-lint -dcmm-lint -dno-debug-output -no-user-package-db -rtsopts -fno-ghci-history ' '/home/a/ghc/ghc-pristine/inplace/bin/ghc-stage2' --interactive -v0 -ignore-dot-ghci -dcore-lint -dcmm-lint -dno-debug-output -no-user-package-db -rtsopts -fno-ghci-history     <ghci023.script >ghci023.run.stdout 2>ghci023.run.stderr
Actual stderr output differs from expected:
--- /dev/null	2013-08-15 19:58:16.771097011 -0500
+++ ./ghci/scripts/ghci023.run.stderr	2013-08-28 20:06:58.525350140 -0500
@@ -0,0 +1,4 @@
+
+<interactive>:14:1: parse error on input `:'
+
+<interactive>:16:1: parse error on input `:'
Actual stdout output differs from expected:
--- ./ghci/scripts/ghci023.stdout	2013-08-22 11:29:40.617737462 -0500
+++ ./ghci/scripts/ghci023.run.stdout	2013-08-28 20:06:58.525350140 -0500
@@ -1,16 +1,5 @@
 -- testing ghci multiline commands :{ .. :}
 -- via stdin
 (1,2,3)
-data Maybe a = Nothing | Just a
-Data.Maybe.catMaybes :: [Maybe a] -> [a]
-Data.Maybe.fromJust :: Maybe a -> a
-Data.Maybe.fromMaybe :: a -> Maybe a -> a
-Data.Maybe.isJust :: Maybe a -> Bool
-Data.Maybe.isNothing :: Maybe a -> Bool
-Data.Maybe.listToMaybe :: [a] -> Maybe a
-Data.Maybe.mapMaybe :: (a -> Maybe b) -> [a] -> [b]
-maybe :: b -> (a -> b) -> Maybe a -> b
-Data.Maybe.maybeToList :: Maybe a -> [a]
 -- via readFile
 (True,False)
-id :: a -> a
*** unexpected failure for ghci023(ghci)
=====> ghci047(ghci) 2684 of 3765 [0, 1, 0]
cd ./ghci/scripts && HC='/home/a/ghc/ghc-pristine/inplace/bin/ghc-stage2' HC_OPTS='-dcore-lint -dcmm-lint -dno-debug-output -no-user-package-db -rtsopts -fno-ghci-history ' '/home/a/ghc/ghc-pristine/inplace/bin/ghc-stage2' --interactive -v0 -ignore-dot-ghci -dcore-lint -dcmm-lint -dno-debug-output -no-user-package-db -rtsopts -fno-ghci-history     <ghci047.script >ghci047.run.stdout 2>ghci047.run.stderr
Actual stderr output differs from expected:
--- ./ghci/scripts/ghci047.stderr	2013-08-22 11:29:40.617737462 -0500
+++ ./ghci/scripts/ghci047.run.stderr	2013-08-28 20:06:58.701349185 -0500
@@ -1,16 +1,29 @@
 
-<interactive>:38:1:
-    Couldn't match type ‛HFalse’ with ‛HTrue’
-    Expected type: HTrue
-      Actual type: Or HFalse HFalse
-    In the expression: f
-    In the expression: f $ Baz 'a'
-    In an equation for ‛it’: it = f $ Baz 'a'
-
-<interactive>:39:1:
-    Couldn't match type ‛HFalse’ with ‛HTrue’
-    Expected type: HTrue
-      Actual type: Or HFalse HFalse
-    In the expression: f
-    In the expression: f $ Quz
-    In an equation for ‛it’: it = f $ Quz
+<interactive>:14:1: parse error on input `data'
+
+<interactive>:35:58:
+    Not in scope: type constructor or class ‛ABorC’
+
+<interactive>:36:1: Not in scope: ‛f’
+
+<interactive>:36:5: Not in scope: data constructor ‛Foo’
+
+<interactive>:37:1: Not in scope: ‛f’
+
+<interactive>:37:5: Not in scope: data constructor ‛Bar’
+
+<interactive>:38:1: Not in scope: ‛f’
+
+<interactive>:38:5: Not in scope: data constructor ‛Baz’
+
+<interactive>:39:1: Not in scope: ‛f’
+
+<interactive>:39:5: Not in scope: data constructor ‛Quz’
+
+<interactive>:40:1: Not in scope: ‛f’
+
+<interactive>:40:5: Not in scope: data constructor ‛Yud’
+
+<interactive>:41:1: Not in scope: ‛f’
+
+<interactive>:41:5: Not in scope: data constructor ‛Myp’
Actual stdout output differs from expected:
--- ./ghci/scripts/ghci047.stdout	2013-08-22 11:29:40.617737462 -0500
+++ ./ghci/scripts/ghci047.run.stdout	2013-08-28 20:06:58.585349815 -0500
@@ -1,4 +0,0 @@
-1
-1
-1
-1
*** unexpected failure for ghci047(ghci)

Unexpected results from:
TEST="ghci023 ghci047"

OVERALL SUMMARY for test run started at Wed Aug 28 20:06:57 CDT 2013
    3765 total tests, which gave rise to
   14933 test cases, of which
   14931 were skipped

       0 had missing libraries
       0 expected passes
       0 expected failures

       0 caused framework failures
       0 unexpected passes
       2 unexpected failures

Unexpected failures:
   ghci/scripts  ghci023 [bad stderr] (ghci)
   ghci/scripts  ghci047 [bad stderr] (ghci)

Can you examine please? The failure to parse data A in ghci047.script seems to indicate to me this is a real failure or some very strange behavioral difference I don't understand at a glance.

This bug also needs to be fixed for 7.8.1 for certain.

Changed 2 years ago by hvr

3rd attempt at fixing stuff; as a side-effect, this one also fixes wrong single-line column-indices in error messages

comment:4 Changed 2 years ago by Herbert Valerio Riedel <hvr@…>

In 43111a0b58f5b2b4cf77b4119bef7b5f3b69d0b3/ghc:

GHCi: Fix multi-line input line/column-number refs

This commit addresses #8051 by fixing

 - Incorrect column indices reported in error messages for
   single-line and multi-line input,

 - incorrect line numbers reported in error messages for
   expressions entered in multi-line input, and

 - inhibiting the confusing interaction between `:{` and `:set +m`
   causing the triggering of implicit multi-line continuation
   mode right after `:}` terminates the multi-line entry block.

comment:5 Changed 2 years ago by thoughtpolice

  • Resolution set to fixed
  • Status changed from patch to closed

Thanks for fixing this Herbert!

Note: See TracTickets for help on using tickets.