application of the record field may fail

Dear Cafe, (ignore following email, but perhaps the observation is still useful, the answer is to use `-Weverything`, which gives more than `-Wall`. Obviously.) For two constructors with fields of identical type but different name, data T = A {foo::()} | B {f00 ::()} GHC detects a typo in the field name ghci> f x = case x of A{f00 = f} -> f ; B {} -> () <interactive>:2:19: error: [GHC-53822] • Constructor ‘A’ does not have field ‘f00’ Good. Now changing the program slightly, ghci> f x = case x of A{} -> f00 x ; B {} -> () the program becomes statically correct. Can we get a warning here? (to detect the typo). This example is close to real code, not foo and f00 but something_longer and something_longerr. Yes I shoudn't do this, and make names more descriptive/distinct. And types! It's only a typo because it's not a type error. [EDIT] the answer is yes, we can, with -Weverything, <interactive>:9:24: warning: [GHC-17335] [-Wincomplete-record-selectors] The application of the record field ‘f00’ may fail for the following constructors: A this sounds over-cautious, because it _will_ fail (if evaluated at all). - J.W.

Yes, I prefer to use mostly -Weverything with maybe 6-8 exceptions, depending on the project. Helps me get out of all sorts of potential accidents. -Wall is definitely not enough for me. I sometimes use -Wwarn in ghcid, so that the app will still reload and let me know what's wrong. Best regards Dan Dart _____ M: (+44) (0)75 075 91874 Callsign: M0ORI Software Engineer, Radio Ham, Musician
participants (2)
-
Dan Dart
-
Johannes Waldmann