Skip to content
  • Ryan Scott's avatar
    Lint types in newFamInst · 257c13d8
    Ryan Scott authored
    We weren't linting the types used in `newFamInst`, which
    might have been why #15012 went undiscovered for so long. Let's fix
    that.
    
    One has to be surprisingly careful with expanding type synonyms in
    `lintType`, since in the offending program (simplified):
    
    ```lang=haskell
    type FakeOut a = Int
    
    type family TF a
    type instance TF Int = FakeOut a
    ```
    
    If one expands type synonyms, then `FakeOut a` will expand to
    `Int`, which masks the issue (that `a` is unbound). I added an
    extra Lint flag to configure whether type synonyms should be
    expanded or not in Lint, and disabled this when calling `lintTypes`
    from `newFamInst`.
    
    As evidence that this works, I ran it on the offending program
    from #15012, and voilà:
    
    ```
    $ ghc3/inplace/bin/ghc-stage2 Bug.hs -dcore-lint
    [1 of 1] Compiling Foo              ( Bug.hs, Bug.o )
    ghc-stage2: panic! (the 'impossible' happened)
      (GHC version 8.5.20180417 for x86_64-unknown-linux):
            Core Lint error
      <no location info>: warning:
          In the type ‘... (Rec0 (FakeOut b_a1Qt))))’
          @ b_a1Qt is out of scope
    ```
    
    Test Plan: make test TEST=T15057
    
    Reviewers: simonpj, goldfire, bgamari
    
    Reviewed By: bgamari
    
    Subscribers: thomie, carter
    
    GHC Trac Issues: #15057
    
    Differential Revision: https://phabricator.haskell.org/D4611
    257c13d8