Skip to content

Detect family instance orphans correctly

Simon Peyton Jones requested to merge wip/T22717 into master

This MR fixes two bugs, both in #22717 (closed)

  1. We were treating a type-family instance as a non-orphan if there was a type constructor on it /right-hand side/ that was local.Boo! Utterly wrong.

    The fix is trivial: look only at the LHS

  2. We were not reporting orphan family instances at all.

    The fix here is easy, but touches more code. I refactored it to be much more similar to the way that class instances are done.

    • Add a fi_orphan field to FamInst, like the is_orphan field in ClsInst
    • Make newFamInst initialise this field, just like newClsInst
    • And make newFamInst report a warning for an orphan, just like newClsInst
    • I moved newFamInst from GHC.Tc.Instance.Family to GHC.Tc.Utils.Instantiate, just like newClsInst.
    • I added mkLocalFamInst to FamInstEnv, just like mkLocalClsInst in InstEnv
    • I added a new error constructor TcRnOrphanFamInst, and renamed the existing TcRnOrphanInstance to TcRnOrphanClsInst
    • Ditto SuggestFixOrphanFamInst
Edited by Simon Peyton Jones

Merge request reports