git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #1566 from purescript/1169
2c7f092Phil Freeman
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
338 Just (_, _, ty, _) -> do
338 Just (_, _, ty, _) -> do
339 (_, fn) <- instantiatePolyTypeWithUnknowns (internalError "Data constructor types cannot contain constraints") ty
339 (_, fn) <- instantiatePolyTypeWithUnknowns (internalError "Data constructor types cannot contain constraints") ty
340 fn' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ fn
340 fn' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ fn
341− go binders fn'
341+ let (args, ret) = peelArgs 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
342+ unless (length args == length binders) . throwError . errorMessage $ IncorrectConstructorArity ctor
343+ ret =?= val
344+ M.unions <$> zipWithM inferBinder (reverse args) binders
352 _ -> throwError . errorMessage $ UnknownDataConstructor ctor Nothing
345 _ -> 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)
353inferBinder val (ObjectBinder props) = do
352inferBinder val (ObjectBinder props) = do
354 row <- fresh
353 row <- fresh
355 rest <- fresh
354 rest <- fresh