Skip to content
  • Simon Peyton Jones's avatar
    Warn about simplifiable class constraints · 9421b0c7
    Simon Peyton Jones authored
    Provoked by Trac #11948, this patch adds a new warning to GHC
    
      -Wsimplifiable-class-constraints
    
    It warns if you write a class constraint in a type signature that
    can be simplified by an existing instance declaration.  Almost always
    this means you should simplify it right now; type inference is very
    fragile without it, as #11948 shows.
    
    I've put the warning as on-by-default, but I suppose that if there are
    howls of protest we can move it out (as happened for -Wredundant-constraints.
    
    It actually found an example of an over-complicated context in CmmNode.
    
    Quite a few tests use these weird contexts to trigger something else,
    so I had to suppress the warning in those.
    
    The 'haskeline' library has a few occurrences of the warning (which
    I think should be fixed), so I switched it off for that library in
    warnings.mk.
    
    The warning itself is done in TcValidity.check_class_pred.
    
    HOWEVER, when type inference fails we get a type error; and the error
    suppresses the (informative) warning.  So as things stand, the warning
    only happens when it doesn't cause a problem.  Not sure what to do
    about this, but this patch takes us forward, I think.
    9421b0c7