Skip to content
  • Bartłomiej Cieślar's avatar
    503fd647
    This MR is an implementation of the proposal #516. · 503fd647
    Bartłomiej Cieślar authored and Marge Bot's avatar Marge Bot committed
    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
    503fd647
    This MR is an implementation of the proposal #516.
    Bartłomiej Cieślar authored and Marge Bot's avatar Marge Bot committed
    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
Loading