Opened 12 months ago

Closed 7 months ago

#11987 closed bug (fixed)

Allow record wildcards with pattern synonyms which are defined in GHCi

Reported by: Iceland_jack Owned by: mpickering
Priority: normal Milestone: 8.0.2
Component: Compiler Version: 8.0.1
Keywords: PatternSynonyms Cc: adamgundry
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D2544
Wiki Page:

Description

With pattern synonym pattern Point {x, y} = (x, y) we can write

>>> let { x = 1; y = 2 } in Point { x = x, y = y }
(1, 2)
>>> let { x = 1; y = 2 } in Point { x, y }
(1, 2)

but record wildcards ain't workin

>>> let { x = 1; y = 2 } in Point {..}
<interactive>:342:25-36: error:
    Pattern synonym Point used as a data constructor

Change History (14)

comment:1 Changed 12 months ago by mpickering

Cc: adamgundry added

I was under the impression that Adam fixed this but maybe it was a different bug.

comment:2 Changed 12 months ago by mpickering

Again, this only happens in ghci.

comment:3 Changed 12 months ago by mpickering

Summary: Allow record wildcards with pattern synonymsAllow record wildcards with pattern synonyms which are defined in GHCi

comment:4 Changed 7 months ago by gelisam

I can reproduce the problem outside of ghci, but only if the pattern synonym is defined in a separate file:

{-# LANGUAGE NamedFieldPuns, PatternSynonyms, RecordWildCards #-}
module Point where

pattern Point :: Int -> Int -> (Int, Int)
pattern Point{x, y} = (x, y)

-- works
sameFile :: (Int,Int)
sameFile = let { x = 1; y = 2 } in Point { .. }
{-# LANGUAGE NamedFieldPuns, PatternSynonyms, RecordWildCards #-}
module Test where

import Point

-- works
namedFieldPuns :: (Int,Int)
namedFieldPuns = let { x = 1; y = 2 } in Point { x, y }

-- error: Pattern synonym ‘Point’ used as a data constructor
recordWildCards :: (Int,Int)
recordWildCards = let { x = 1; y = 2 } in Point { .. }

comment:5 Changed 7 months ago by mpickering

Owner: set to mpickering

Fix is easy. Sorry for not looking sooner.

comment:6 Changed 7 months ago by mpickering

Status: newpatch

Would be good to merge I think Ben.

comment:7 Changed 7 months ago by simonpj

You've put it in patch status, but I see no patch

comment:8 Changed 7 months ago by mpickering

Differential Rev(s): Phab:D2544

comment:9 Changed 7 months ago by mpickering

Ah, I was mistaken, there is two separate problems here. The patch fixes the second on reported today but the first one is a different issue.

comment:10 Changed 7 months ago by simonpj

What is "first" and "second"?

comment:11 Changed 7 months ago by mpickering

The patch fixes comment:4 but doesn't fix the case where a user defines a record pattern synonym in the GHCi prompt.

To be specific, here is the exact example which still fails.

*Test Prelude> pattern P{x} = Just x
*Test Prelude> let x=5 in P{..}

<interactive>:8:12: error:
    Illegal `..' notation for constructor ‘P’
      The constructor has no labelled fields

It seems that tcg_field_env is not updated properly somewhere with the record pattern synonym selectors.

comment:12 Changed 7 months ago by Ben Gamari <ben@…>

In 2d6642b/ghc:

Fix interaction of record pattern synonyms and record wildcards

We were missing an appropiate *ConLike lookup in the case when
the pattern synonym was defined in a different module.

Reviewers: austin, bgamari, simonpj

Reviewed By: simonpj

Subscribers: simonpj, thomie

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

GHC Trac Issues: #11987

comment:13 Changed 7 months ago by bgamari

Milestone: 8.0.2
Status: patchmerge
Version: 8.18.0.1

comment:14 Changed 7 months ago by bgamari

Resolution: fixed
Status: mergeclosed
Note: See TracTickets for help on using tickets.