This MR is an implementation of the proposal #516.
It adds a warning -Wincomplete-record-selectors for usages of a record field access function (either a record selector or getField @"rec"), while trying to silence the warning whenever it can be sure that a constructor without the record field would not be invoked (which would otherwise cause the program to fail). For example: data T = T1 | T2 {x :: Bool} f a = x a -- this would throw an error g T1 = True g a = x a -- this would not throw an error h :: HasField "x" r Bool => r -> Bool h = getField @"x" j :: T -> Bool j = h -- this would throw an error because of the `HasField` -- constraint being solved See the tests DsIncompleteRecSel* and TcIncompleteRecSel for more examples of the warning. See Note [Detecting incomplete record selectors] in GHC.HsToCore.Expr for implementation details
parent
fac9e84e
No related branches found
No related tags found
Checking pipeline status
Showing
- compiler/GHC/Core/ConLike.hs 5 additions, 2 deletionscompiler/GHC/Core/ConLike.hs
- compiler/GHC/Driver/Flags.hs 2 additions, 0 deletionscompiler/GHC/Driver/Flags.hs
- compiler/GHC/Driver/Session.hs 2 additions, 1 deletioncompiler/GHC/Driver/Session.hs
- compiler/GHC/HsToCore/Errors/Ppr.hs 6 additions, 0 deletionscompiler/GHC/HsToCore/Errors/Ppr.hs
- compiler/GHC/HsToCore/Errors/Types.hs 18 additions, 0 deletionscompiler/GHC/HsToCore/Errors/Types.hs
- compiler/GHC/HsToCore/Expr.hs 55 additions, 3 deletionscompiler/GHC/HsToCore/Expr.hs
- compiler/GHC/HsToCore/Monad.hs 14 additions, 0 deletionscompiler/GHC/HsToCore/Monad.hs
- compiler/GHC/HsToCore/Pmc.hs 90 additions, 7 deletionscompiler/GHC/HsToCore/Pmc.hs
- compiler/GHC/HsToCore/Pmc/Check.hs 19 additions, 1 deletioncompiler/GHC/HsToCore/Pmc/Check.hs
- compiler/GHC/HsToCore/Pmc/Types.hs 5 additions, 1 deletioncompiler/GHC/HsToCore/Pmc/Types.hs
- compiler/GHC/HsToCore/Pmc/Utils.hs 1 addition, 0 deletionscompiler/GHC/HsToCore/Pmc/Utils.hs
- compiler/GHC/IfaceToCore.hs 10 additions, 1 deletioncompiler/GHC/IfaceToCore.hs
- compiler/GHC/Tc/Errors/Ppr.hs 7 additions, 0 deletionscompiler/GHC/Tc/Errors/Ppr.hs
- compiler/GHC/Tc/Errors/Types.hs 18 additions, 0 deletionscompiler/GHC/Tc/Errors/Types.hs
- compiler/GHC/Tc/Instance/Class.hs 10 additions, 2 deletionscompiler/GHC/Tc/Instance/Class.hs
- compiler/GHC/Tc/Solver/Dict.hs 2 additions, 2 deletionscompiler/GHC/Tc/Solver/Dict.hs
- compiler/GHC/Tc/Solver/Monad.hs 3 additions, 3 deletionscompiler/GHC/Tc/Solver/Monad.hs
- compiler/GHC/Tc/TyCl/Utils.hs 9 additions, 4 deletionscompiler/GHC/Tc/TyCl/Utils.hs
- compiler/GHC/Types/Error.hs 5 additions, 0 deletionscompiler/GHC/Types/Error.hs
- compiler/GHC/Types/Error/Codes.hs 2 additions, 0 deletionscompiler/GHC/Types/Error/Codes.hs
Loading