Opened 4 years ago

Closed 4 years ago

#10743 closed bug (invalid)

Data declaration order matters to compiler.

Reported by: thomaseding Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.8.3
Keywords: Cc:
Operating System: Windows Architecture: Unknown/Multiple
Type of failure: GHC rejects valid program Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


{-# LANGUAGE TemplateHaskell #-}

import Control.Lens.TH (makeLenses)

data Handle h where
    PlayerHandle :: Int -> Handle Player

    -- GHC 7.8.3 complains that NonPlayer is not in scope
    NonPlayerHandle :: Int -> Handle NonPlayer

data Player = Player

-- Deferring this until after NonPlayer is defined, resolves the compile error.
-- Commenting this out also works.
makeLenses ''Player

data NonPlayer

(The exact version of 'lens' I have tried this with is 'lens-4.7' if that matters.)

Change History (1)

comment:1 Changed 4 years ago by bgamari

Resolution: invalid
Status: newclosed

This is (arguably unfortunately) the expected behavior. See the discussion of "declaration groups" in Section 7.17.1 of the User's Guide.

In short, splices delimit groups of declarations. Declarations can only be recursive within their group. The usual solution here would be to move the makeLenses splice after the data NonPlayer definition.

Note: See TracTickets for help on using tickets.