Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change missing-fields warning to an error in GHC

I'm using GHC on haskell-stack project. I'd like to lift missing-fields warning up to a compile error.

I tried to do the following, but it doesn't work.

{-# OPTIONS_GHC -Werror=missing-fields #-} -- DOESN'T WORK

Could you tell how to lift missing fields warning up to a compile error?

like image 741
ryo Avatar asked Oct 21 '17 14:10

ryo


2 Answers

This only works in GHC 8.2.1 and above. If you're using stack, the current LTS resolver is only on 8.0.2. Either update your GHC (in stack, that would be setting compiler: ghc-8.2.1), or just make all warnings into errors with -Werror -Wmissing-fields, and sit tight until the feature is more widely available. (If you trigger another warning, say missing-methods, it stays a warning in the former, but becomes an error in the latter.)

like image 174
HTNW Avatar answered Sep 18 '22 11:09

HTNW


Just make fields strict. This is a good practice in general because it helps to avoid space leaks and can lead to other optimizations. In case you don't really rely on laziness, you can convert fields to strict.

like image 28
Shersh Avatar answered Sep 20 '22 11:09

Shersh