type IsString + test unification error

This commit is contained in:
crumbtoo
2023-12-18 11:22:40 -07:00
parent 0470912983
commit e9e1c075db
3 changed files with 16 additions and 4 deletions

View File

@@ -1,4 +1,4 @@
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE QuasiQuotes, OverloadedStrings #-}
module Core.HindleyMilnerSpec
( spec
)
@@ -6,7 +6,7 @@ module Core.HindleyMilnerSpec
----------------------------------------------------------------------------------
import Core.Syntax
import Core.TH (coreExpr)
import Core.HindleyMilner (infer)
import Core.HindleyMilner (infer, TypeError(..), HMError)
import Test.Hspec
----------------------------------------------------------------------------------
@@ -14,6 +14,14 @@ import Test.Hspec
spec :: Spec
spec = do
it "should infer `id 3` :: Int" $
let g = [ ("id", TyVar "a" :-> TyVar "a") ]
let g = [ ("id", "a" :-> "a") ]
in infer g [coreExpr|id 3|] `shouldBe` Right TyInt
it "should not infer `id 3` when `id` is specialised to `a -> a`" $
let g = [ ("id", ("a" :-> "a") :-> "a" :-> "a") ]
in infer g [coreExpr|id 3|] `shouldSatisfy` isUntypedVariableErr
isUntypedVariableErr :: HMError a -> Bool
isUntypedVariableErr (Left (TyErrCouldNotUnify _ _)) = True
isUntypedVariableErr _ = False