From: simonmar Date: Fri, 2 Jun 2000 12:19:40 +0000 (+0000) Subject: [project @ 2000-06-02 12:19:40 by simonmar] X-Git-Tag: Approximately_9120_patches~4328 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=2c26e7307deaf25b39ba616940667c6657161e45;p=ghc-hetmet.git [project @ 2000-06-02 12:19:40 by simonmar] checkTyCon shouldn't look through newtypes. Instead, we add a new function checkRepTyCon which does, and use it in the few cases where it is needed. This fixes a nasty bug with overloaded literals of newtypes, and probably a whole bunch of other lurking bugs too. --- diff --git a/ghc/compiler/prelude/TysWiredIn.lhs b/ghc/compiler/prelude/TysWiredIn.lhs index a2b6ae3..7a809e3 100644 --- a/ghc/compiler/prelude/TysWiredIn.lhs +++ b/ghc/compiler/prelude/TysWiredIn.lhs @@ -349,21 +349,25 @@ being the ) \begin{code} isFFIArgumentTy :: Bool -> Type -> Bool -- Checks for valid argument type for a 'foreign import' -isFFIArgumentTy is_safe ty = checkTyCon (legalOutgoingTyCon is_safe) ty +isFFIArgumentTy is_safe ty = checkRepTyCon (legalOutgoingTyCon is_safe) ty isFFIExternalTy :: Type -> Bool -- Types that are allowed as arguments of a 'foreign export' -isFFIExternalTy ty = checkTyCon legalIncomingTyCon ty +isFFIExternalTy ty = checkRepTyCon legalIncomingTyCon ty isFFIResultTy :: Type -> Bool -- Types that are allowed as a result of a 'foreign import' or of a 'foreign export' -- Maybe we should distinguish between import and export, but -- here we just choose the more restrictive 'incoming' predicate -- But we allow () as well -isFFIResultTy ty = checkTyCon (\tc -> tc == unitTyCon || legalIncomingTyCon tc) ty +isFFIResultTy ty = checkRepTyCon (\tc -> tc == unitTyCon || legalIncomingTyCon tc) ty + +checkRepTyCon :: (TyCon -> Bool) -> Type -> Bool + -- look through newtypes +checkRepTyCon check_tc ty = checkTyCon check_tc (repType ty) checkTyCon :: (TyCon -> Bool) -> Type -> Bool -checkTyCon check_tc ty = case splitTyConApp_maybe (repType ty) of +checkTyCon check_tc ty = case splitTyConApp_maybe ty of Just (tycon, _) -> check_tc tycon Nothing -> False