Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#5746 closed feature request (fixed)

-Werror should wait until type-checking is done

Reported by: lerkok Owned by:
Priority: normal Milestone: 7.2.1
Component: Compiler Version: 7.2.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

I'm a big fan of "-Wall -Werror". I find that the warnings GHC generates are well worth fixing.

With -Werror, GHC currently stops the compilation right when it detects a warning. This does sound reasonable, but it makes for a bad user experience. Consider:

foo :: Int -> Float
foo x = x
 where c _ = 2.3

The *real* mistake here is that I should've said c x on the right hand side, not just x. But with -Werror, GHC will first complain that c is defined but not used, stopping the compilation right there, without telling me that there's a type-error. If I go ahead and delete the definition for 'c' to take care of the warning and compile again, I'll get the actual type error. By then, I realize the real problem was that I forgot to call 'c', whose definition I just deleted. Easy to fix (if you've source control at least), but pretty bad user experience.

(Surprisingly, this scenario happens quite often in code maintenance, definitely way more often than I'd have thought..)

A better alternative would be to *delay* the stopping effect of -Werror until after type-checking is complete. That is,-Werror should continue until after type-checking is completely done and thus give GHC a chance to print type-errors, and then stop the compilation if there were any warnings. The chances are that once the actual errors are fixed, the warning will disappear. This'd save quite a number of edit-compile cycles, increasing the user-experience greatly.

Change History (4)

comment:1 Changed 8 years ago by simonmar

difficulty: Unknown
Milestone: 7.2.1
Resolution: fixed
Status: newclosed

I think I fixed this in 7.2. With 7.2 and later you see the type error, not the warning. See #1666.

comment:2 Changed 8 years ago by simonpj

I think the author wanted both type error and warning; but generally GHC suppresses warnings if there are any type errors.

comment:3 Changed 8 years ago by simonmar

Generally speaking it's a bad idea to print warnings and errors together, because you always need to fix the errors first, and the warnings just get in the way. We could make it optional I suppose, but I don't think Levent is asking for that, he just wants the type error rather than the warning (and I agree - it was a real bug, which is now fixed).

comment:4 Changed 8 years ago by lerkok

Great to hear this is addressed in 7.2! (I'm still on 7.0.4 due to the platform delay.) Thanks.

Regarding printing both warnings and errors: I don't think warnings would get in the way, so long as the error message clearly stands out as the *last* thing GHC utters before it stops. I find myself only looking at the very last thing printed most of the time. Printing the warnings would be just as fine, so long as they all precede the final error message. Individual preferences might differ of course.

Note: See TracTickets for help on using tickets.