From 657154910055616d6c7ed11c06653ab0897f5020 Mon Sep 17 00:00:00 2001 From: sof <unknown> Date: Wed, 17 Dec 1997 20:04:34 +0000 Subject: [PATCH] [project @ 1997-12-17 20:04:34 by sof] Better error message when trying to declare CCallable & CReturnable instance of abstract type --- ghc/compiler/typecheck/TcInstDcls.lhs | 28 +++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/ghc/compiler/typecheck/TcInstDcls.lhs b/ghc/compiler/typecheck/TcInstDcls.lhs index 1057e4997dd0..02a257f1637b 100644 --- a/ghc/compiler/typecheck/TcInstDcls.lhs +++ b/ghc/compiler/typecheck/TcInstDcls.lhs @@ -689,6 +689,17 @@ scrutiniseInstanceType dfun_name clas inst_tau && all isTyVarTy arg_tys = failTc (derivingWhenInstanceExistsErr clas inst_tycon) + | -- CCALL CHECK + -- To verify that a user declaration of a CCallable/CReturnable + -- instance is OK, we must be able to see the constructor(s) + -- of the instance type (see next guard.) + -- + -- We flag this separately to give a more precise error msg. + -- + (uniqueOf clas == cCallableClassKey && not constructors_visible) || + (uniqueOf clas == cReturnableClassKey && not constructors_visible) + = failTc (invisibleDataConPrimCCallErr clas inst_tau) + | -- CCALL CHECK -- A user declaration of a CCallable/CReturnable instance -- must be for a "boxed primitive" type. @@ -705,6 +716,11 @@ scrutiniseInstanceType dfun_name clas inst_tau inst_tycon = expectJust "tcInstDecls1:inst_tycon" inst_tycon_maybe (_, tyvar_dups) = removeDups cmp (map (getTyVar "tcInstDecls1:getTyVarTy") arg_tys) + constructors_visible = + case maybeAppDataTyCon inst_tau of + Just (_,_,[]) -> False + everything_else -> True + -- These conditions come directly from what the DsCCall is capable of. -- Totally grotesque. Green card should solve this. @@ -756,6 +772,18 @@ nonBoxedPrimCCallErr clas inst_ty sty 4 (hsep [ ptext SLIT("class"), ppr sty clas, ptext SLIT("type"), ppr sty inst_ty]) +{- + Declaring CCallable & CReturnable instances in a module different + from where the type was defined. Caused by importing data type + abstractly (either programmatically or by the renamer being over-eager + in its pruning.) +-} +invisibleDataConPrimCCallErr clas inst_ty sty + = hang (hsep [(ppr sty inst_ty <> ptext SLIT("s constructors not visible when checking")), + ppr sty clas, ptext SLIT("instance")]) + 4 (hsep [ptext SLIT("(Try either importing"), ppr sty inst_ty, + ptext SLIT("non-abstractly, or compile using -fno-prune-tydecls ..)")]) + omittedMethodWarn sel_id clas sty = sep [ptext SLIT("Warning: no explicit method nor default method for") <+> ppr sty sel_id, ptext SLIT("in an instance declaration for") <+> ppr sty clas] -- GitLab