I got another idea based on (ab?) Using the GHC -fdefer-type-errors option, which may be cheaper than implementing a full Haskell interpreter, for example using hint . Its output is a bit messy because warnings are still printed at compile time, but you can clear it if you want to disable warnings in general using the GHC -w option in both the file and the ghc command line.
Although I am including everything to demonstrate this in one module here, I believe that the parameters of this test should be correctly included in the corresponding test module.
Please note that this method depends on how capable it is to sufficiently deeply assess the value of the violation in order to identify deferred errors that can be difficult in some cases.
{-# OPTIONS_GHC -fdefer-type-errors #-} {-# LANGUAGE TypeOperators, GADTs, DataKinds #-} {-# LANGUAGE StandaloneDeriving #-} import GHC.TypeLits import Control.Exception import Data.Typeable data Vector nt where EmptyVec :: Vector 0 t ConsVec :: t -> Vector nt -> Vector (n+1) t -- Add a Show instance so we can evaluate a Vector deeply to catch any -- embedded deferred type errors. deriving instance Show t => Show (Vector nt) illegalVec = ConsVec 'c' (ConsVec "b" EmptyVec) test = do t <- try . evaluate $ length (show illegalVec) case t of Right _ -> error "Showing illegalVec gave no error" Left e -> putStrLn $ "\nOk: Showing illegalVec returned error:\n" ++ show (e :: ErrorCall) -- ErrorCall is the exception type returned by the error function and seems -- also to be used by deferred type errors.
source share