git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix #1570
724ac1dPhil Freeman
examples/failing/1570.pursnew file+6
@@ -0,0 +1,6 @@
1+-- @shouldFailWith ExpectedType
2+module M where
3+
4+data F a = F a
5+
6+test = \(x :: F) -> x
examples/passing/1570.pursnew file+6
@@ -0,0 +1,6 @@
1+module Main where
2+
3+test :: forall a. a -> a
4+test = \(x :: a) -> x
5+
6+main = Control.Monad.Eff.Console.log "Done"
psci/PSCi.hs+1−1
@@ -425,7 +425,7 @@ handleKindOf typ = do
425 case M.lookup (P.Qualified (Just mName) $ P.ProperName "IT") (P.typeSynonyms env') of
425 case M.lookup (P.Qualified (Just mName) $ P.ProperName "IT") (P.typeSynonyms env') of
426 Just (_, typ') -> do
426 Just (_, typ') -> do
427 let chk = P.CheckState env' 0 0 (Just mName)
427 let chk = P.CheckState env' 0 0 (Just mName)
428− k = fst . runWriter . runExceptT $ L.runStateT (P.unCheck (P.kindOf mName typ')) chk
428+ k = fst . runWriter . runExceptT $ L.runStateT (P.unCheck (P.kindOf typ')) chk
429 case k of
429 case k of
430 Left errStack -> PSCI . outputStrLn . P.prettyPrintMultipleErrors False $ errStack
430 Left errStack -> PSCI . outputStrLn . P.prettyPrintMultipleErrors False $ errStack
431 Right (kind, _) -> PSCI . outputStrLn . P.prettyPrintKind $ kind
431 Right (kind, _) -> PSCI . outputStrLn . P.prettyPrintKind $ kind
src/Language/PureScript/TypeChecker.hs+1−1
@@ -206,7 +206,7 @@ typeCheckAll moduleName _ ds = mapM go ds <* mapM_ checkOrphanFixities ds
206 go (d@(ExternDeclaration name ty)) = do
206 go (d@(ExternDeclaration name ty)) = do
207 warnAndRethrow (addHint (ErrorInForeignImport name)) $ do
207 warnAndRethrow (addHint (ErrorInForeignImport name)) $ do
208 env <- getEnv
208 env <- getEnv
209− kind <- kindOf moduleName ty
209+ kind <- kindOf ty
210 guardWith (errorMessage (ExpectedType ty kind)) $ kind == Star
210 guardWith (errorMessage (ExpectedType ty kind)) $ kind == Star
211 case M.lookup (moduleName, name) (names env) of
211 case M.lookup (moduleName, name) (names env) of
212 Just _ -> throwError . errorMessage $ RedefinedIdent name
212 Just _ -> throwError . errorMessage $ RedefinedIdent name
src/Language/PureScript/TypeChecker/Kinds.hs+2−2
@@ -76,8 +76,8 @@ instance Unifiable Check Kind where
76-- |
76-- |
77-- Infer the kind of a single type
77-- Infer the kind of a single type
78--
78--
79−kindOf :: ModuleName -> Type -> Check Kind
79+kindOf :: Type -> Check Kind
80−kindOf _ ty = fst <$> kindOfWithScopedVars ty
80+kindOf ty = fst <$> kindOfWithScopedVars ty
81
81
82-- |
82-- |
83-- Infer the kind of a single type, returning the kinds of any scoped type variables
83-- Infer the kind of a single type, returning the kinds of any scoped type variables
src/Language/PureScript/TypeChecker/Skolems.hs+9−4
@@ -72,11 +72,16 @@ skolemize ident sko scope = replaceTypeVars ident (Skolem ident sko scope)
72-- only example of scoped type variables.
72-- only example of scoped type variables.
73--
73--
74skolemizeTypesInValue :: String -> Int -> SkolemScope -> Expr -> Expr
74skolemizeTypesInValue :: String -> Int -> SkolemScope -> Expr -> Expr
75−skolemizeTypesInValue ident sko scope = let (_, f, _) = everywhereOnValues id go id in f
75+skolemizeTypesInValue ident sko scope = let (_, f, _) = everywhereOnValues id onExpr onBinder in f
76 where
76 where
77+ onExpr :: Expr -> Expr
77− go (SuperClassDictionary c ts) = SuperClassDictionary c (map (skolemize ident sko scope) ts)
78+ onExpr (SuperClassDictionary c ts) = SuperClassDictionary c (map (skolemize ident sko scope) ts)
78− go (TypedValue check val ty) = TypedValue check val (skolemize ident sko scope ty)
79+ onExpr (TypedValue check val ty) = TypedValue check val (skolemize ident sko scope ty)
80+ onExpr other = other
81+
82+ onBinder :: Binder -> Binder
83+ onBinder (TypedBinder ty b) = TypedBinder (skolemize ident sko scope ty) b
79− go other = other
84+ onBinder other = other
80
85
81-- |
86-- |
82-- Ensure skolem variables do not escape their scope
87-- Ensure skolem variables do not escape their scope
src/Language/PureScript/TypeChecker/Types.hs+8−4
@@ -373,11 +373,15 @@ inferBinder val (NamedBinder name binder) = do
373 return $ M.insert name val m
373 return $ M.insert name val m
374inferBinder val (PositionedBinder pos _ binder) =
374inferBinder val (PositionedBinder pos _ binder) =
375 warnAndRethrowWithPosition pos $ inferBinder val binder
375 warnAndRethrowWithPosition pos $ inferBinder val binder
376−-- TODO: When adding support for polymorphic types, check subsumption here
376+-- TODO: When adding support for polymorphic types, check subsumption here,
377−-- and change the definition of `binderRequiresMonotype`
377+-- change the definition of `binderRequiresMonotype`,
378+-- and use `kindOfWithScopedVars`.
378inferBinder val (TypedBinder ty binder) = do
379inferBinder val (TypedBinder ty binder) = do
379− ty' <- replaceAllTypeSynonyms ty
380+ ty1 <- replaceAllTypeSynonyms <=< replaceTypeWildcards $ ty
381+ kind <- liftCheck $ kindOf ty1
382+ checkTypeKind ty1 kind
383+ val =?= ty1
380− val =?= ty' >> inferBinder val binder
384+ inferBinder val binder
381
385
382-- | Returns true if a binder requires its argument type to be a monotype.
386-- | Returns true if a binder requires its argument type to be a monotype.
383-- | If this is the case, we need to instantiate any polymorphic types before checking binders.
387-- | If this is the case, we need to instantiate any polymorphic types before checking binders.