Opened 12 years ago

Closed 9 years ago

#2245 closed bug (fixed)

Numeric literal printed wrong in error message

Reported by: guest Owned by:
Priority: normal Milestone: 7.2.1
Component: Compiler Version: 6.9
Keywords: Cc: lennart@…
Operating System: MacOS X Architecture: x86
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


Compile the following with -Wall

default (T)

data T = T deriving (Eq, Ord, Read, Show)
instance Num T
instance Fractional T

main = interact $ show . (< 1e400) . read

The error message says

    Warning: Defaulting the following constraint(s) to type `T'
             `Fractional b'
               arising from the literal `Infinity' at Bug.hs:7:28-32

There is no literal Infinity in my program, I wrote 1e400, which could be a perfectly good literal for the type T. I don't wanted printed as Infinity.

Change History (9)

comment:1 Changed 12 years ago by simonpj

difficulty: Unknown

cf #1861, which is related.

Nevertheless this ticket is a distinct bug in GHC's error message.


comment:2 Changed 12 years ago by simonpj

Milestone: 6.10 branch
Priority: normallow

The underlying problem here is this. The lexer sees the token


and from that produces a Rational. See Lexer.x, and the function readRational. In this case it'll produce something like

15 :% 100000

The trouble is that when printing it out in an error message, it's hard to reverse-engineer that into exactly what the programmer wrote. What we do at the moment (in Pretty.rational) is to convert to Double and show that. This will go wrong if there isn't an exact representation for the constant in Double -- and that's what is happening to Lennart.

The Right Thing is for a HsLit.HsFractional to contain not a Rational, but rather something like a

data FloatLit 
  = FL { fl_int :: Integer         -- Part before decimal point
       , fl_frac :: Maybe Integer  -- Part after decimal point (if any)
       , fl_exp  :: Maybe Integer  -- Exponent (if any)

This would record exactly what the user wrote. Then we can convert to a Rational later, but meanwhile we can print it accurately in error messages.

Simple, but a bit fiddly, so I'm not going to do it today. The above notes just record the plan. Yell if it's important to get it done sooner.


comment:3 Changed 11 years ago by igloo

Milestone: 6.10 branch6.12 branch

comment:4 Changed 10 years ago by igloo

Milestone: 6.12 branch6.12.3

comment:5 Changed 10 years ago by igloo

Priority: lownormal
Type of failure: None/Unknown

comment:6 Changed 10 years ago by igloo

See also #2911.

comment:7 Changed 9 years ago by igloo


comment:8 Changed 9 years ago by igloo


comment:9 Changed 9 years ago by batterseapower

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.