Opened 3 years ago

Closed 3 years ago

#12003 closed bug (fixed)

Improve error message about closed variables

Reported by: facundo.dominguez Owned by:
Priority: normal Milestone: 8.2.1
Component: Compiler Version: 8.1
Keywords: StaticPointers Cc: mboes
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: #11656 Differential Rev(s): Phab:D2167
Wiki Page:

Description (last modified by facundo.dominguez)

After allowing local bindings in static definitions the following program

{-# LANGUAGE StaticPointers #-}
module M where

f x = static g
  where
    g = h
    h = x

yields the error

../tmp/M.hs:4:7: error:
    • ‘g’ is used in a static form but it is not closed.
    • In the expression: static g
      In an equation for ‘f’:
          f x
            = static g
            where
                g = h
                h = x

where it would be more helpful to get a message like

../tmp/M.hs:4:7: error:
    • ‘g’ is used in a static form but it is not closed because it
      uses ‘h’ which uses ‘x’ which is not let-bound.
    • In the expression: static g
      In an equation for ‘f’:
          f x
            = static g
            where
                g = h
                h = x

Change History (4)

comment:1 Changed 3 years ago by facundo.dominguez

Description: modified (diff)
Differential Rev(s): Phab:D2167
Status: newpatch

comment:2 Changed 3 years ago by facundo.dominguez

Cc: mboes added

comment:3 Changed 3 years ago by Ben Gamari <ben@…>

In e9dfb6e/ghc:

Improve the error messages for static forms.

Now the message explains why closed variables are not closed when
encountered in the body of (static ...).

This required adding to the local environment the free variables of
the local bindings in scope. Thus we can analyze and explain why a
variable is not closed when encountered.

Test Plan: ./validate

Reviewers: austin, simonpj, bgamari

Reviewed By: bgamari

Subscribers: mboes, thomie

Differential Revision: https://phabricator.haskell.org/D2167

GHC Trac Issues: #12003

comment:4 Changed 3 years ago by bgamari

Milestone: 8.2.1
Resolution: fixed
Status: patchclosed
Note: See TracTickets for help on using tickets.