Skip to content
  • Simon Peyton Jones's avatar
    Make better "fake tycons" in error recovery · 2f6069cc
    Simon Peyton Jones authored
    Consider (Trac #15215)
      data T a = MkT ...
      data S a = ...T...MkT....
    
    If there is an error in the definition of 'T' we add a
    "fake type constructor" to the type environment, so that we
    can continue to typecheck 'S'.  But we /were not/ adding
    a fake anything for 'MkT' and so there was an internal
    error when we met 'MkT' in the body of 'S'.
    
    The fix is to add fake tycons for all the 'implicits' of 'T'.
    This is done by mk_fake_tc in TcTyClsDecls.checkValidTyCl,
    which now returns a /list/ of TyCons rather than just one.
    
    On the way I did some refactoring:
    
    * Rename TcTyDecls.tcAddImplicits to tcAddTyConsToGblEnv
      and make it /include/ the TyCons themeselves as well
      as their implicits
    
    * Some incidental refactoring about tcRecSelBinds. The main
      thing is that I've avoided creating a HsValBinds that we
      immediately decompose.  That meant moving some deck chairs
      around.
    
    NB: The new error message for the regression test T15215
    has the opaque error "Illegal constraint in a type:", flagged
    in Trac #14845.  But that's the fault of the latter ticket.
    The fix here not to blame.
    2f6069cc