File tree Expand file tree Collapse file tree
src/Language/PureScript/TypeChecker Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ -- @shouldFailWith IncorrectConstructorArity
2+ module Test where
3+
4+ data Outer a = Outer a
5+
6+ data Inner a b = Inner a b
7+
8+ test1 :: forall a b . Outer (Inner a b ) -> Boolean
9+ test1 (Outer (Inner _)) = true
10+
11+ test2 :: forall a b . Inner a b -> Boolean
12+ test2 (Inner _) = true
Original file line number Diff line number Diff line change @@ -338,18 +338,17 @@ inferBinder val (ConstructorBinder ctor binders) = do
338338 Just (_, _, ty, _) -> do
339339 (_, fn) <- instantiatePolyTypeWithUnknowns (internalError " Data constructor types cannot contain constraints" ) ty
340340 fn' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ fn
341- go binders fn'
342- where
343- go [] ty' = case (val, ty') of
344- (TypeConstructor _, TypeApp _ _) -> throwIncorrectArity
345- _ -> do
346- _ <- val =?= ty'
347- return M. empty
348- go (binder : binders') (TypeApp (TypeApp t obj) ret) | t == tyFunction =
349- M. union <$> inferBinder obj binder <*> go binders' ret
350- go _ _ = throwIncorrectArity
351- throwIncorrectArity = throwError . errorMessage $ IncorrectConstructorArity ctor
341+ let (args, ret) = peelArgs fn'
342+ unless (length args == length binders) . throwError . errorMessage $ IncorrectConstructorArity ctor
343+ ret =?= val
344+ M. unions <$> zipWithM inferBinder (reverse args) binders
352345 _ -> throwError . errorMessage $ UnknownDataConstructor ctor Nothing
346+ where
347+ peelArgs :: Type -> ([Type ], Type )
348+ peelArgs = go []
349+ where
350+ go args (TypeApp (TypeApp fn arg) ret) | fn == tyFunction = go (arg : args) ret
351+ go args ret = (args, ret)
353352inferBinder val (ObjectBinder props) = do
354353 row <- fresh
355354 rest <- fresh
You can’t perform that action at this time.
0 commit comments