git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #1566 from purescript/1169

Fix #1169

commit2c7f09292648249d9e3dabdd79cad2b26e75a15e authorPhil Freeman <paf31@cantab.net> dateMon 26 Oct 2015, 09:33 (11 years ago) parent0fc5d6b8d0963c
2 files changed+22−11
examples/failing/1169.purs+12 src/Language/PureScript/TypeChecker/Types.hs+10−11
examples/failing/1169.pursnew file+12
@@ -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+10−11
@@ -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