Opened 2 years ago

Closed 2 years ago

#10997 closed bug (fixed)

Pattern synonym causes Iface error.

Reported by: mpickering Owned by:
Priority: high Milestone: 7.10.3
Component: Compiler Version: 7.10.2
Keywords: PatternSynonyms Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: patsyn/should_compile/T10997, T10997_1
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description (last modified by mpickering)

From the mailing list..

Hello, We have a pattern synonym as follows

type family Showable (a :: k) :: Constraint where
  Showable (a :: *) = (Show a)
  Showable a       = ()

pattern Just' :: () => (Showable a) => a -> (Maybe a)
pattern Just' a <- (extractJust -> (True, a)) where
  Just' a = Just a

When we try to use the pattern in a different package, the error was

    [1 of 1] Compiling Bar              ( Bar.hs, .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/Bar.o )
    /tmp/test/p2/.stack-work/install/x86_64-linux/lts-3.5/7.10.2/lib/x86_64-linux-ghc-7.10.2/p1-0.1.0.0-I5t4il6dN7vIqsT1XgYsM3/Foo.hi
    Declaration for Just'
    Pattern synonym Just':
      Iface type variable out of scope:  k
    Cannot continue after interface file error

The error only occurred when Showable was polykinded and we used synonym in a different package . Using the synonym in the same package works fine.

This problem did not happen with the following definition of (non polykinded ) Showable

type family Showable a :: Constraint where
  Showable a = (Show a)

Attachments (1)

bug.tar.gz (2.1 KB) - added by mpickering 2 years ago.

Download all attachments as: .zip

Change History (13)

comment:1 Changed 2 years ago by mpickering

Description: modified (diff)

comment:2 Changed 2 years ago by simonpj

Does this amount to a reproducible test case? What is Bar.hs?

Changed 2 years ago by mpickering

Attachment: bug.tar.gz added

comment:3 Changed 2 years ago by mpickering

Yes, see the attached file and run "stack build" in p2/ is one way.

Another way to trigger it is to have, two files Foo.hs and Bar.hs as follows. Then run the following commands..

ghc Foo.hs
ghc Bar.hs
[2 of 2] Compiling Bar              ( Bar.hs, Bar.o )
The interface for ‘Foo’
Declaration for Just'
Pattern synonym Just':
  Iface type variable out of scope:  k
Cannot continue after interface file error
{-# LANGUAGE PatternSynonyms, ViewPatterns, ConstraintKinds, TypeFamilies, PolyKinds, KindSignatures #-}
module Foo where

import GHC.Exts

type family Showable (a :: k) :: Constraint where
  Showable (a :: *) = (Show a)
  Showable a       = ()

extractJust :: Maybe a -> (Bool, a)
extractJust (Just a) = (True, a)
extractJust _        = (False, undefined)

pattern Just' :: () => (Showable a) => a -> (Maybe a)
pattern Just' a <- (extractJust -> (True, a)) where
  Just' a = Just a
module Bar where

import Foo

bar :: (Showable a) => Maybe a -> Maybe a
bar (Just' a) = Just' a
Last edited 2 years ago by mpickering (previous) (diff)

comment:4 Changed 2 years ago by Thomas Miedema <thomasmiedema@…>

In 68a084f/ghc:

Testsuite: add test for #10997

comment:5 Changed 2 years ago by thomie

Keywords: PatternSynonyms added
Test Case: typecheck/should_compile/T10997

comment:6 Changed 2 years ago by Iceland_jack

I am also affected by this bug when using -fobject-code.

Given

{-# LANGUAGE GADTs, PatternSynonyms #-}

module Foo where

data Exp ty where
  LitB :: Bool -> Exp Bool

pattern Tru :: b ~ Bool => Exp b
pattern Tru = LitB True

and

module Bar where

import Foo

foo :: Exp a -> String
foo Tru = "True"

results in the following session:

% ghci -ignore-dot-ghci
GHCi, version 7.10.2: http://www.haskell.org/ghc/  :? for help
Prelude> :load Bar
[1 of 2] Compiling Foo              ( Foo.hs, interpreted )
[2 of 2] Compiling Bar              ( Bar.hs, interpreted )
Ok, modules loaded: Bar, Foo.
*Bar> :set -fobject-code 
*Bar> :load Foo
[1 of 1] Compiling Foo              ( Foo.hs, Foo.o )
Ok, modules loaded: Foo.
Prelude Foo> :load Bar
[2 of 2] Compiling Bar              ( Bar.hs, Bar.o )
The interface for ‘Foo’
Declaration for Tru
Pattern synonym Tru:
  Iface type variable out of scope:  k
Cannot continue after interface file error
> 

comment:7 Changed 2 years ago by Iceland_jack

Also simply triggered by:

% ghc Foo      
[1 of 1] Compiling Foo              ( Foo.hs, Foo.o )
% ghc Bar
[2 of 2] Compiling Bar              ( Bar.hs, Bar.o )
The interface for ‘Foo’
Declaration for Tru
Pattern synonym Tru:
  Iface type variable out of scope:  k
Cannot continue after interface file error

which causes some tension in my own projects where I use pattern synonyms generously.

Last edited 2 years ago by Iceland_jack (previous) (diff)

comment:8 Changed 2 years ago by mpickering

Priority: normalhigh

comment:9 Changed 2 years ago by Simon Peyton Jones <simonpj@…>

In 0ce858e5/ghc:

Zonk properly when checkig pattern synonyms

Fixes Trac #10997

Merge to stable branch

comment:10 Changed 2 years ago by simonpj

Status: newmerge
Test Case: typecheck/should_compile/T10997patsyn/should_compile/T10997, T10997_1

Thanks for reporting this.

comment:11 Changed 2 years ago by thoughtpolice

Milestone: 7.10.3

comment:12 Changed 2 years ago by bgamari

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