Opened 4 years ago

Closed 4 years ago

#5334 closed bug (fixed)

record wildcards: field not initialised reported as type error

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


I think that the following program should be accepted, with warnings about not initialized fields:

{-# LANGUAGE RecordWildCards #-}

data T = T { a, b :: Int }

t = T {..}
     a = 1
     -- b = 2

data S = S { x, y :: Int }

s = S { x = 1 }

but it produces

$ ghci bugrecord.hs
GHCi, version 7.0.4:  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
[1 of 1] Compiling Main             ( bugrecord.hs, interpreted )

    Couldn't match expected type `Int' with actual type `T -> Int'
    In the `b' field of a record
    In the expression: T {..}
    In an equation for `t':
        t = T {..}
              a = 1
Failed, modules loaded: none.

If we uncomment the definition of field b the program is accepted, with a correct warning about the undefined field y in the other record.

Change History (4)

comment:1 Changed 4 years ago by simonpj

  • Owner set to simonpj

good idea. I'll do this.

comment:2 Changed 4 years ago by simonpj@…

commit 5d89565b043eaff9028205b79363ef0d0c17ff17

Author: Simon Peyton Jones <[email protected]>
Date:   Wed Jul 20 15:38:58 2011 +0100

    Improve semantics of wild-card expansion (fixes #5334)
    When expanding the {..} stuff in an *expression*, take
    account of which variables are in scope.
    I updated the documentation, and in doing so found that
    part of the previously-documented semantics wasn't implemented
    (namely the stuff about fields in scope), so I fixed that too.

 compiler/rename/RnEnv.lhs         |   43 ++++++++++++++++-----------
 compiler/rename/RnPat.lhs         |   57 ++++++++++++++++++++++++++-----------
 docs/users_guide/glasgow_exts.xml |   33 ++++++++++++++++-----
 3 files changed, 90 insertions(+), 43 deletions(-)

comment:3 Changed 4 years ago by simonpj

  • Status changed from new to merge

Merge, perhaps?

comment:4 Changed 4 years ago by igloo

  • Resolution set to fixed
  • Status changed from merge to closed
Note: See TracTickets for help on using tickets.