Skip to content

Accessing shadowed definitions in GHCi

Apparently GHCi creates a qualified namespace for each line it interprets, as can be observed with:

> data A = A
> data A = B
> :t A
A :: Ghci3.A

Apparently accessing shadowed definitions in this way sometimes breaks GHCi:

> let a = a
> let a = a
> :t Ghci7.a

<interactive>:1:1: error:
     GHC internal error: Ghci7.a is not in scope during type checking, but it passed the renamer
      tcl_env of environment: []
     In the expression: Ghci7.a

More specifically, complete reproduction instructions:

GHCi, version 8.1.20160205: http://www.haskell.org/ghc/  :? for help
> let foo = foo
> :t Ghci1.foo
Ghci1.foo :: t
> let foo = foo
> :t Ghci1.foo

<interactive>:1:1: error:
     GHC internal error: Ghci1.foo is not in scope during type checking, but it passed the renamer
      tcl_env of environment: []
     In the expression: Ghci1.foo
  1. 10.2 (and 7.8.3 as verified over IRC by monochrom) appears to have a slightly different behavior. It seems it only creates namespaces for data/newtype/class declarations. Yet still, it fails with an error the first time but works completely fine thereafter:
> data A = A
> data A = A
> :t Ghci1.A
Failed to load interface for Ghci1
no package key matching interactive was found
> :t Ghci1.A
Ghci1.A :: Ghci1.A
  1. 6.3 uses a different approach to displaying out of scope names so the behavior doesn't apply:
> data A = A
> data A = B
> :t A
A :: main::Interactive.A
Trac metadata
Trac field Value
Version 8.0.1-rc1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component GHCi
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