checkDictTy :: LHsType RdrName -> P (LHsType RdrName)
checkDictTy (L spn ty) = check ty []
where
- check (HsTyVar t) args | not (isRdrTyVar t)
- = return (L spn (HsPredTy (HsClassP t args)))
+ check (HsTyVar tc) args | isRdrTc tc = done tc args
+ check (HsOpTy t1 (L _ tc) t2) args | isRdrTc tc = done tc (t1:t2:args)
check (HsAppTy l r) args = check (unLoc l) (r:args)
check (HsParTy t) args = check (unLoc t) args
check _ _ = parseError spn "Malformed instance header"
+ done tc args = return (L spn (HsPredTy (HsClassP tc args)))
+
checkTParams :: Bool -- Type/data family
-> [LHsType RdrName]
-> P ([LHsTyVarBndr RdrName], Maybe [LHsType RdrName])
checkValSig (L l (HsVar v)) ty
| isUnqual v && not (isDataOcc (rdrNameOcc v))
= return (TypeSig (L l v) ty)
-checkValSig (L l _) _
+checkValSig lhs@(L l _) _
+ | looks_like_foreign lhs
+ = parseError l "Invalid type signature; perhaps you meant to use -XForeignFunctionInterface?"
+ | otherwise
= parseError l "Invalid type signature"
+ where
+ -- A common error is to forget the ForeignFunctionInterface flag
+ -- so check for that, and suggest. cf Trac #3805
+ -- Sadly 'foreign import' still barfs 'parse error' because 'import' is a keyword
+ looks_like_foreign (L _ (HsVar v)) = v == foreign_RDR
+ looks_like_foreign (L _ (HsApp lhs _)) = looks_like_foreign lhs
+ looks_like_foreign _ = False
+
+ foreign_RDR = mkUnqual varName (fsLit "foreign")
\end{code}
-- The Maybe is because the user can omit the activation spec (and usually does)
mkInlinePragma mb_act match_info inl
= InlinePragma { inl_inline = inl
+ , inl_sat = Nothing
, inl_act = act
, inl_rule = match_info }
where