@@ -286,27 +286,54 @@ typeCheckModule (Module ss coms mn decls (Just exps)) = warnAndRethrow (addHint
286286 modify (\s -> s { checkCurrentModule = Just mn })
287287 decls' <- typeCheckAll mn exps decls
288288 forM_ exps $ \e -> do
289+ checkTypesAreExported e
289290 checkClassMembersAreExported e
290291 checkClassesAreExported e
291292 return $ Module ss coms mn decls' (Just exps)
292293 where
293294
294295 checkMemberExport :: (Type -> [DeclarationRef]) -> DeclarationRef -> Check ()
296+ checkMemberExport extract dr@(TypeRef name dctors) = do
297+ env <- getEnv
298+ case M.lookup (Qualified (Just mn) name) (typeSynonyms env) of
299+ Nothing -> return ()
300+ Just (_, ty) -> checkExport dr extract ty
301+ case dctors of
302+ Nothing -> return ()
303+ Just dctors' -> forM_ dctors' $ \dctor ->
304+ case M.lookup (Qualified (Just mn) dctor) (dataConstructors env) of
305+ Nothing -> return ()
306+ Just (_, _, ty, _) -> checkExport dr extract ty
307+ return ()
295308 checkMemberExport extract dr@(ValueRef name) = do
296309 ty <- lookupVariable mn (Qualified (Just mn) name)
297− case filter (not . exported) (extract ty) of
298− [] -> return ()
299− hidden -> throwError . errorMessage $ TransitiveExportError dr hidden
300− where
301− exported e = any (exports e) exps
302− exports (TypeRef pn1 _) (TypeRef pn2 _) = pn1 == pn2
303− exports (ValueRef id1) (ValueRef id2) = id1 == id2
304− exports (TypeClassRef pn1) (TypeClassRef pn2) = pn1 == pn2
305− exports (PositionedDeclarationRef _ _ r1) r2 = exports r1 r2
306− exports r1 (PositionedDeclarationRef _ _ r2) = exports r1 r2
307− exports _ _ = False
310+ checkExport dr extract ty
308311 checkMemberExport _ _ = return ()
309312
313+ checkExport :: DeclarationRef -> (Type -> [DeclarationRef]) -> Type -> Check ()
314+ checkExport dr extract ty = case filter (not . exported) (extract ty) of
315+ [] -> return ()
316+ hidden -> throwError . errorMessage $ TransitiveExportError dr hidden
317+ where
318+ exported e = any (exports e) exps
319+ exports (TypeRef pn1 _) (TypeRef pn2 _) = pn1 == pn2
320+ exports (ValueRef id1) (ValueRef id2) = id1 == id2
321+ exports (TypeClassRef pn1) (TypeClassRef pn2) = pn1 == pn2
322+ exports (PositionedDeclarationRef _ _ r1) r2 = exports r1 r2
323+ exports r1 (PositionedDeclarationRef _ _ r2) = exports r1 r2
324+ exports _ _ = False
325+
326+ -- Check that all the type constructors defined in the current module that appear in member types
327+ -- have also been exported from the module
328+ checkTypesAreExported :: DeclarationRef -> Check ()
329+ checkTypesAreExported = checkMemberExport findTcons
330+ where
331+ findTcons :: Type -> [DeclarationRef]
332+ findTcons = everythingOnTypes (++) go
333+ where
334+ go (TypeConstructor (Qualified (Just mn') name)) | mn' == mn = [TypeRef name (error "Data constructors unused in checkTypesAreExported")]
335+ go _ = []
336+
310337 -- Check that all the classes defined in the current module that appear in member types have also
311338 -- been exported from the module
312339 checkClassesAreExported :: DeclarationRef -> Check ()