[GHC] #13068: GHC should not allow modules to define instances of abstract type classes

GHC ghc-devs at haskell.org
Fri Mar 10 17:19:40 UTC 2017


#13068: GHC should not allow modules to define instances of abstract type classes
-------------------------------------+-------------------------------------
        Reporter:  ezyang            |                Owner:  (none)
            Type:  bug               |               Status:  closed
        Priority:  low               |            Milestone:  8.2.1
       Component:  Compiler (Type    |              Version:  8.1
  checker)                           |
      Resolution:  fixed             |             Keywords:  backpack
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  GHC accepts       |  Unknown/Multiple
  invalid program                    |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):  Phab:D3254
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Changes (by bgamari):

 * status:  patch => closed
 * resolution:   => fixed


Old description:

> hs-boot files permit a type class to be given "abstractly", in which case
> any implementation of the type class is permissible. But it does not
> reject instances defined for such a class.
>
> {{{
> -- A.hs-boot
> module A where
> class C a
>
> -- B.hs
> module B where
> import {-# SOURCE #-} A
> instance C Int where
>
> -- A.hs
> module A where
> import B
> class C a where
>     f :: a
>
> -- Main.hs
> import A
> main = print (f :: Int)
> }}}
>
> I get this when I build with `--make`:
>
> {{{
> ezyang at sabre:~$ ghc-head --make C.hs -fforce-recomp
> [1 of 4] Compiling A[boot]          ( A.hs-boot, A.o-boot )
> [2 of 4] Compiling B                ( B.hs, B.o )
> [3 of 4] Compiling A                ( A.hs, A.o )
> [4 of 4] Compiling Main             ( C.hs, C.o )
> Linking C ...
> ./B.o:(.data+0x0): undefined reference to `A_CZCC_con_info'
> collect2: error: ld returned 1 exit status
> }}}

New description:

 hs-boot files permit a type class to be given "abstractly", in which case
 any implementation of the type class is permissible. But it does not
 reject instances defined for such a class.

 {{{#!hs
 -- A.hs-boot
 module A where
 class C a

 -- B.hs
 module B where
 import {-# SOURCE #-} A
 instance C Int where

 -- A.hs
 module A where
 import B
 class C a where
     f :: a

 -- Main.hs
 import A
 main = print (f :: Int)
 }}}

 I get this when I build with `--make`:

 {{{
 ezyang at sabre:~$ ghc-head --make C.hs -fforce-recomp
 [1 of 4] Compiling A[boot]          ( A.hs-boot, A.o-boot )
 [2 of 4] Compiling B                ( B.hs, B.o )
 [3 of 4] Compiling A                ( A.hs, A.o )
 [4 of 4] Compiling Main             ( C.hs, C.o )
 Linking C ...
 ./B.o:(.data+0x0): undefined reference to `A_CZCC_con_info'
 collect2: error: ld returned 1 exit status
 }}}

--

Comment:

 This was resolved in bba004f2a0642d3bb8c8876543aaa1a48a2f9a43.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13068#comment:4>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list