git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #489 from purescript/480
c64d07fPhil Freeman
examples/passing/Rank2Object.pursnew file+10
@@ -0,0 +1,10 @@
1+module Main where
2+
3+import Debug.Trace
4+
5+data Foo = Foo { id :: forall a. a -> a }
6+
7+foo :: Foo -> Number
8+foo (Foo { id = f }) = f 0
9+
10+main = trace "Done"
src/Language/PureScript/TypeChecker/Types.hs+5−4
@@ -728,7 +728,7 @@ inferBinder val (ConstructorBinder ctor binders) = do
728 case M.lookup ctor (dataConstructors env) of
728 case M.lookup ctor (dataConstructors env) of
729 Just (_, ty) -> do
729 Just (_, ty) -> do
730 (_, fn) <- instantiatePolyTypeWithUnknowns (error "Data constructor types cannot contain constraints") ty
730 (_, fn) <- instantiatePolyTypeWithUnknowns (error "Data constructor types cannot contain constraints") ty
731− fn' <- replaceAllTypeSynonyms fn
731+ fn' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ fn
732 go binders fn'
732 go binders fn'
733 where
733 where
734 go [] ty' = do
734 go [] ty' = do
@@ -1005,7 +1005,9 @@ checkProperties ps row lax = let (ts, r') = rowToList row in go ps ts r' where
1005-- Check the type of a function application, rethrowing errors to provide a better error message
1005-- Check the type of a function application, rethrowing errors to provide a better error message
1006--
1006--
1007checkFunctionApplication :: Value -> Type -> Value -> Maybe Type -> UnifyT Type Check (Type, Value)
1007checkFunctionApplication :: Value -> Type -> Value -> Maybe Type -> UnifyT Type Check (Type, Value)
1008−checkFunctionApplication fn fnTy arg ret = rethrow (mkErrorStack errorMessage (Just (ValueError fn)) <>) $ checkFunctionApplication' fn fnTy arg ret
1008+checkFunctionApplication fn fnTy arg ret = rethrow (mkErrorStack errorMessage (Just (ValueError fn)) <>) $ do
1009+ subst <- unifyCurrentSubstitution <$> UnifyT get
1010+ checkFunctionApplication' fn (subst $? fnTy) arg (($?) subst <$> ret)
1009 where
1011 where
1010 errorMessage = "Error applying function of type "
1012 errorMessage = "Error applying function of type "
1011 ++ prettyPrintType fnTy
1013 ++ prettyPrintType fnTy
@@ -1018,8 +1020,7 @@ checkFunctionApplication' :: Value -> Type -> Value -> Maybe Type -> UnifyT Type
1018checkFunctionApplication' fn (TypeApp (TypeApp tyFunction' argTy) retTy) arg ret = do
1020checkFunctionApplication' fn (TypeApp (TypeApp tyFunction' argTy) retTy) arg ret = do
1019 tyFunction' =?= tyFunction
1021 tyFunction' =?= tyFunction
1020 _ <- maybe (return Nothing) (subsumes Nothing retTy) ret
1022 _ <- maybe (return Nothing) (subsumes Nothing retTy) ret
1021− subst <- unifyCurrentSubstitution <$> UnifyT get
1022− arg' <- check arg (subst $? argTy)
1023+ arg' <- check arg argTy
1023 return (retTy, App fn arg')
1024 return (retTy, App fn arg')
1024checkFunctionApplication' fn (ForAll ident ty _) arg ret = do
1025checkFunctionApplication' fn (ForAll ident ty _) arg ret = do
1025 replaced <- replaceVarWithUnknown ident ty
1026 replaced <- replaceVarWithUnknown ident ty