Skip to content

Wacky error message when RULE mentions out-of-scope variable

If I compile the following program with GHC 8.4 or later:

module Foo where

{-# RULES "test" forall x. f x = x #-}

The error message I get is somewhat eyebrow-raising:

$ /opt/ghc/8.4.3/bin/ghc Foo.hs
[1 of 1] Compiling Foo              ( Foo.hs, Foo.o )

Foo.hs:3:11: error:
    Rule "test":
        Not in scope: OutOfScope(f)
        in left-hand side: f x
    LHS must be of form (f e1 .. en) where f is not forall'd
  |
3 | {-# RULES "test" forall x. f x = x #-}
  |           ^^^^^^^^^^^^^^^^^^^^^^^^

I'm not sure what this OutOfScope business is, but I doubt we want to be referring to it in error messages. The error in GHC 8.2 and earlier was much less confusing:

$ /opt/ghc/8.2.2/bin/ghc Foo.hs
[1 of 1] Compiling Foo              ( Foo.hs, Foo.o )

Foo.hs:3:11: error:
    Rule "test":
        Not in scope: f
        in left-hand side: f x
    LHS must be of form (f e1 .. en) where f is not forall'd
  |
3 | {-# RULES "test" forall x. f x = x #-}
  |           ^^^^^^^^^^^^^^^^^^^^^^^^
Trac metadata
Trac field Value
Version 8.4.3
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information