@@ -1,6 +1,7 @@
11{-# LANGUAGE ScopedTypeVariables #-}
22{-# LANGUAGE FlexibleInstances #-}
33{-# LANGUAGE FlexibleContexts #-}
4+{-# LANGUAGE PatternGuards #-}
45
56-- |
67-- The top-level type checker, which checks all declarations in a module.
@@ -438,22 +439,32 @@ typeCheckModule (Module ss coms mn decls (Just exps)) = warnAndRethrow (addHint
438439
439440 checkNonAliasesAreExported :: [ProperName 'ConstructorName] -> DeclarationRef -> m ()
440441 checkNonAliasesAreExported exportedDctors dr@(ValueRef (Op name)) =
441− case listToMaybe (mapMaybe getAlias decls) of
442− Just (AliasValue ident) ->
442+ case listToMaybe (mapMaybe (getAlias getValueAlias name) decls) of
443+ Just (Left ident) ->
443444 unless (ValueRef ident `elem` exps) $
444445 throwError . errorMessage $ TransitiveExportError dr [ValueRef ident]
445− Just (AliasConstructor ctor) ->
446+ Just (Right ctor) ->
446447 unless (ctor `elem` exportedDctors) $
447448 throwError . errorMessage $ TransitiveDctorExportError dr ctor
448449 _ -> return ()
450+ checkNonAliasesAreExported _ dr@(TypeOpRef (Op name)) =
451+ case listToMaybe (mapMaybe (getAlias getTypeAlias name) decls) of
452+ Just ty ->
453+ unless (any (isTypeRefFor ty) exps) $
454+ throwError . errorMessage $ TransitiveExportError dr [TypeRef ty Nothing]
455+ _ -> return ()
449456 where
450− getAlias :: Declaration -> Maybe FixityAlias
451− getAlias (PositionedDeclaration _ _ d) = getAlias d
452− getAlias (FixityDeclaration _ name' (Just (Qualified (Just mn') alias)))
453− | name == name' && mn == mn' = Just alias
454− getAlias _ = Nothing
457+ isTypeRefFor :: ProperName 'TypeName -> DeclarationRef -> Bool
458+ isTypeRefFor ty (TypeRef ty' _) = ty == ty'
459+ isTypeRefFor _ _ = False
455460 checkNonAliasesAreExported _ _ = return ()
456461
462+ getAlias :: (FixityAlias -> Maybe a) -> String -> Declaration -> Maybe a
463+ getAlias match name (PositionedDeclaration _ _ d) = getAlias match name d
464+ getAlias match name (FixityDeclaration _ name' (Just (Qualified (Just mn') a)))
465+ | Just alias <- match a, name == name' && mn == mn' = Just alias
466+ getAlias _ _ _ = Nothing
467+
457468 exportedDataConstructors :: [DeclarationRef] -> [ProperName 'ConstructorName]
458469 exportedDataConstructors = foldMap extractCtor
459470 where