Opened 3 years ago

Last modified 16 months ago

#13584 new bug

ghci parse error on operator info

Reported by: akegalj Owned by:
Priority: lowest Milestone:
Component: GHCi Version: 8.0.2
Keywords: parse, info, operator Cc:
Operating System: Linux Architecture: x86_64 (amd64)
Type of failure: Incorrect result at runtime Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description (last modified by akegalj)

If requested info about some operator, ie (+) :info (+) is working as expected:

> :i (+)
class Num a where
  (+) :: a -> a -> a
  ...
        -- Defined in ‘GHC.Num’
infixl 6 +

When additional space character is there :info (+ ) it won't parse:

> :i (+ )

<interactive>:1:3: error:
    parse error (possibly incorrect indentation or mismatched brackets)

Note that the same thing is working with :type so its strange it doesn't use the same parser in both places:

> :t (+ )
(+ ) :: Num a => a -> a -> a

Change History (5)

comment:1 Changed 3 years ago by akegalj

Description: modified (diff)

comment:2 Changed 2 years ago by bgamari

It is indeed strange that these parse differently. I would argue that we should reject (+ ).

comment:3 Changed 16 months ago by anarchist666

The words operator is used in the :info command.

info :: Bool -> String -> InputT GHCi ()
info _ "" = throwGhcException (CmdLineError "syntax: ':i <thing-you-want-info-about>'")
info allInfo s  = handleSourceError GHC.printException $ do
    unqual <- GHC.getPrintUnqual
    dflags <- getDynFlags
    sdocs  <- mapM (infoThing allInfo) (words s)
mapM_ (liftIO . putStrLn . showSDocForUser dflags unqual) sdocs

But you can type :info + - and get this

class Num a where
  (+) :: a -> a -> a
  ...
        -- Defined in ‘GHC.Num’
infixl 6 +
class Num a where
  (-) :: a -> a -> a
  ...
        -- Defined in ‘GHC.Num’
infixl 6 -

We can remove all brackets in the input line, but I want to know what the others think about it.

Last edited 16 months ago by anarchist666 (previous) (diff)

comment:4 Changed 16 months ago by bgamari

Alright, looking at the report again I suppose accepting (+ ) is reasonable; afterall whitespace is not allowed in identifiers; it's merely a lexeme delimiter. I rescind comment:2.

comment:5 Changed 16 months ago by bgamari

anarchist666, I'm not sure I understand your proposal. Are you suggesting that :info simply drop all parentheses from its arguments?

Note: See TracTickets for help on using tickets.