Warn about incomplete NamedFieldPuns patterns
In certain situations it's nice to be able to ensure that record pattern matches are exhaustive:
data R = R {a, b :: Int}
-- should warn
f R{a} = a
-- should not warn
g R{a, b} = a + b
-- should not warn
h R{a, ..} = a + b
-- should not warn
i R{a, b = _} = a
It's useful when there are several functions that inspect a record (e.g. handlers that update a subset of fields in a database) and we want to make certain that when a new field is added to the record, the programmer won't forget to update functions working with that record (either by handling the field or explicitly discarding it). Currently the only non-hacky way to do it is writing f (R a _) = ...
, which is obviously not ideal.
Trac metadata
Trac field | Value |
---|---|
Version | 8.6.1 |
Type | FeatureRequest |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |