Skip to content

Commit 2c7f092

Browse files
committed
Merge pull request purescript#1566 from purescript/1169
Fix purescript#1169
2 parents 0fc5d6b + 8d0963c commit 2c7f092

2 files changed

Lines changed: 22 additions & 11 deletions

File tree

examples/failing/1169.purs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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

src/Language/PureScript/TypeChecker/Types.hs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff 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)
353352
inferBinder val (ObjectBinder props) = do
354353
row <- fresh
355354
rest <- fresh

0 commit comments

Comments
 (0)