Skip to content

Cross-module SPECIALZE pragmas aren't typechecked in -O0

If a module defines a SPECIALIZE pragma for a value defined in another module, then the signature of this pragma won't be typecheck by ghc -O0 (but it will be if the SPECIALIZE pragma is in the same module as the value).

For example, given

-- Foo.hs
module Foo where

foo :: a -> a
foo = id


----------
-- Bar.hs
module Bar where

import Foo

{-# SPECIALIZE foo :: Int -> Bool #-}

running ghc --make Bar.hs will run fine, while ghc --make -O2 Bar.hs will complain:

Bar.hs:5:1: error:
    • Couldn't match type ‘Bool’ with ‘Int’
      Expected type: Int -> Int
        Actual type: Int -> Bool
    • In the SPECIALISE pragma {-# SPECIALIZE foo :: Int -> Bool #-}
  |
5 | {-# SPECIALIZE foo :: Int -> Bool #-}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Tested on ghc 8.6.1 and 8.4.3

Trac metadata
Trac field Value
Version 8.6.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler (Type checker)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information