git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Disallow polymorphic types in binders, prevent internalError (#2624)
0eb180cPhil Freeman
examples/docs/src/ExplicitTypeSignatures.purs−2
@@ -14,5 +14,3 @@ anInt = 0
14
14
15-- This should infer a type.
15-- This should infer a type.
16aNumber = 1.0
16aNumber = 1.0
17−
18−foreign import nestedForAll :: forall c. (forall a b. c)
examples/failing/2445.pursnew file+6
@@ -0,0 +1,6 @@
1+-- @shouldFailWith ErrorParsingModule
2+module Main where
3+
4+data X a = X
5+
6+eg = \(X :: (forall a. X a)) -> X
src/Language/PureScript/TypeChecker/Types.hs+3−5
@@ -487,15 +487,12 @@ inferBinder val (NamedBinder name binder) = do
487 return $ M.insert name val m
487 return $ M.insert name val m
488inferBinder val (PositionedBinder pos _ binder) =
488inferBinder val (PositionedBinder pos _ binder) =
489 warnAndRethrowWithPositionTC pos $ inferBinder val binder
489 warnAndRethrowWithPositionTC pos $ inferBinder val binder
490−-- TODO: When adding support for polymorphic types, check subsumption here,
491−-- change the definition of `binderRequiresMonotype`,
492−-- and use `kindOfWithScopedVars`.
493inferBinder val (TypedBinder ty binder) = do
490inferBinder val (TypedBinder ty binder) = do
494 kind <- kindOf ty
491 kind <- kindOf ty
495 checkTypeKind ty kind
492 checkTypeKind ty kind
496− ty1 <- replaceAllTypeSynonyms <=< replaceTypeWildcards $ ty
493+ ty1 <- introduceSkolemScope <=< replaceAllTypeSynonyms <=< replaceTypeWildcards $ ty
497 unifyTypes val ty1
494 unifyTypes val ty1
498− inferBinder val binder
495+ inferBinder ty1 binder
499inferBinder _ OpBinder{} =
496inferBinder _ OpBinder{} =
500 internalError "OpBinder should have been desugared before inferBinder"
497 internalError "OpBinder should have been desugared before inferBinder"
501inferBinder _ BinaryNoParensBinder{} =
498inferBinder _ BinaryNoParensBinder{} =
@@ -510,6 +507,7 @@ binderRequiresMonotype NullBinder = False
510binderRequiresMonotype (VarBinder _) = False
507binderRequiresMonotype (VarBinder _) = False
511binderRequiresMonotype (NamedBinder _ b) = binderRequiresMonotype b
508binderRequiresMonotype (NamedBinder _ b) = binderRequiresMonotype b
512binderRequiresMonotype (PositionedBinder _ _ b) = binderRequiresMonotype b
509binderRequiresMonotype (PositionedBinder _ _ b) = binderRequiresMonotype b
510+binderRequiresMonotype (TypedBinder ty b) = isMonoType ty || binderRequiresMonotype b
513binderRequiresMonotype _ = True
511binderRequiresMonotype _ = True
514
512
515-- | Instantiate polytypes only when necessitated by a binder.
513-- | Instantiate polytypes only when necessitated by a binder.
src/Language/PureScript/Types.hs+2
@@ -127,6 +127,8 @@ rowFromList ((name, t):ts, r) = RCons name t (rowFromList (ts, r))
127--
127--
128isMonoType :: Type -> Bool
128isMonoType :: Type -> Bool
129isMonoType ForAll{} = False
129isMonoType ForAll{} = False
130+isMonoType (ParensInType t) = isMonoType t
131+isMonoType (KindedType t _) = isMonoType t
130isMonoType _ = True
132isMonoType _ = True
131
133
132-- |
134-- |
tests/TestDocs.hs−1
@@ -336,7 +336,6 @@ testCases =
336 [ ValueShouldHaveTypeSignature (n "ExplicitTypeSignatures") "explicit" (ShowFn (hasTypeVar "something"))
336 [ ValueShouldHaveTypeSignature (n "ExplicitTypeSignatures") "explicit" (ShowFn (hasTypeVar "something"))
337 , ValueShouldHaveTypeSignature (n "ExplicitTypeSignatures") "anInt" (ShowFn (P.tyInt ==))
337 , ValueShouldHaveTypeSignature (n "ExplicitTypeSignatures") "anInt" (ShowFn (P.tyInt ==))
338 , ValueShouldHaveTypeSignature (n "ExplicitTypeSignatures") "aNumber" (ShowFn (P.tyNumber ==))
338 , ValueShouldHaveTypeSignature (n "ExplicitTypeSignatures") "aNumber" (ShowFn (P.tyNumber ==))
339− , ValueShouldHaveTypeSignature (n "ExplicitTypeSignatures") "nestedForAll" (renderedType "forall c. (forall a b. c)")
340 ])
339 ])
341
340
342 , ("ConstrainedArgument",
341 , ("ConstrainedArgument",