[GHC] #10569: Treat an out-of-scope variable like a typed hole

GHC ghc-devs at haskell.org
Fri Jun 26 07:32:43 UTC 2015


#10569: Treat an out-of-scope variable like a typed hole
-------------------------------------+-------------------------------------
        Reporter:  simonpj           |                   Owner:
            Type:  feature request   |                  Status:  new
        Priority:  normal            |               Milestone:
       Component:  Compiler          |                 Version:  7.10.1
      Resolution:                    |                Keywords:
Operating System:  Unknown/Multiple  |            Architecture:
 Type of failure:  None/Unknown      |  Unknown/Multiple
      Blocked By:                    |               Test Case:
 Related Tickets:                    |                Blocking:
                                     |  Differential Revisions:
-------------------------------------+-------------------------------------

Comment (by Simon Peyton Jones <simonpj@…>):

 In [changeset:"fb7b6922573af76a954d939c85e6af7c39a19896/ghc"]:
 {{{
 #!CommitTicketReference repository="ghc"
 revision="fb7b6922573af76a954d939c85e6af7c39a19896"
 Treat out-of-scope variables as holes

 This patch implements the idea in Trac #10569.

 * An out-of-scope variable is treated as a typed expression
   hole.

 * That is, we don't report it in the type checker, not the
   renamer, and we when we do report it, we give its type.

 * Moreover, we can defer the error to runtime with
   -fdefer-typed-holes

 In implementation terms:

 * The renamer turns an unbound variable into a HsUnboundVar

 * The type checker emits a Hole constraint for a
   HsUnboundVar, and turns it back into a HsVar

 It was a bit painful to implement because a whole raft of
 error messages change slightly.  But there was absolutely
 nothing hard in principle.

 Holes are reported with a bunch of possibly-useful context,
 notably the "relevant bindings".  I found that this was
 distracting clutter in the very common case of a mis-typed
 variable that is only accidentally not in scope, so I've
 arranged to print the context information only for true holes,
 that is ones starting with an underscore.

 Unbound data constructors use in patterns, like
   f (D x) = x
 are still reportd by the renamer, and abort compilation
 before type checking.
 }}}

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10569#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list