#10873 closed bug (fixed)

Bad error message for incorrect pattern synonym signature

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

Description (last modified by mpickering)

Consider the following program

{-# LANGUAGE PatternSynonyms #-}

pattern Pat :: () => Show a => a -> Maybe a
pattern Pat a = Just a

GHC complains that

test.hs:4:9: No instance for (Show a) arising from a pattern

I think this is quite difficult to understand. The problem is that matching on Just a doesn't provide the show constraint (it provides no constraints). A better error message here would explain this fact and maybe a short explanation of the difference between prov/req in a pattern synonym signature.

Change History (11)

comment:1 Changed 18 months ago by goldfire

Ich. Agreed that the error message is terrible. Also agreed with your analysis of this (confusing) situation.

comment:2 Changed 17 months ago by mpickering

Another note: there is another bad error message when there is an arity mismatch. Seems like some contexts need to be sprinkled in relevant places.

comment:3 Changed 14 months ago by ak3n

Is it okay that GHC (master head) compiles it without problems now?

Build of fork with test:

https://travis-ci.org/ak3n/ghc/jobs/98938720

Commit:

https://github.com/ak3n/ghc/commit/aee63f611b30164cc1c828a66d22e6e7302af385

comment:4 Changed 14 months ago by mpickering

The error should now be triggered by switching around the constraints.

{-# LANGUAGE PatternSynonyms #-}

pattern Pat :: () => Show a => a -> Maybe a
pattern Pat a = Just a

comment:5 Changed 14 months ago by mpickering

I just tried this with a recent version of HEAD and there is still the same bad error.

comment:6 Changed 14 months ago by mpickering

Description: modified (diff)

comment:7 Changed 13 months ago by rdragon

Owner: set to rdragon

comment:8 Changed 13 months ago by simonpj

Keywords: PatternSynonyms added; newcomer removed

comment:9 Changed 13 months ago by thomie

Differential Rev(s): Phab:D1866

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

In 116528c/ghc:

Improve pattern synonym error messages (add `PatSynOrigin`)

Adds a new data constructor `PatSynOrigin Bool Name` to the `CtOrigin`
data type. This allows for better error messages when the origin of a
wanted constraint is a pattern synonym declaration.

Fixes T10873.

Reviewers: mpickering, simonpj, austin, thomie, bgamari

Reviewed By: simonpj, thomie, bgamari

Subscribers: thomie

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

GHC Trac Issues: #10873

comment:11 Changed 12 months ago by bgamari

Resolution: fixed
Status: newclosed

This is greatly improved with the patch in comment:10. The original example now fails with,

Hi.hs:6:22: error:
    • No instance for (Show a)
        arising from the "provided" constraints claimed by
          the signature of ‘Pat’
      In other words, a successful match on the pattern
        Just a
      does not provide the constraint (Show a)
    • In the declaration for pattern synonym ‘Pat’
Note: See TracTickets for help on using tickets.