import TcHsSyn ( mkHsTyLam, mkHsDictLam, tcIdType,
TcHsBinds, TcMonoBinds
)
-import BasicTypes ( RecFlag(..) )
+import BasicTypes ( RecFlag(..), NewOrData(..) )
import Inst ( newDicts, InstOrigin(..), Inst )
import TcMonoType ( tcHsTypeKind, tcHsType, tcContext )
import Type ( typeKind, getTyVar, tyVarsOfTypes, splitSigmaTy,
mkTyConApp, mkTyVarTys, mkForAllTys, mkFunTy,
splitFunTys, mkTyVarTy, getTyVar_maybe,
- Type, ThetaType
+ isUnboxedType, Type, ThetaType
)
import TyVar ( tyVarKind, elementOfTyVarSet, intersectTyVarSets, isEmptyTyVarSet,
TyVar )
\begin{code}
tcTyDecl is_rec (TyData data_or_new context tycon_name tyvar_names con_decls derivings pragmas src_loc)
= tcAddSrcLoc src_loc $
- tcAddErrCtxt (tyDataCtxt tycon_name) $
+ let ctxt = case data_or_new of
+ NewType -> tyNewCtxt tycon_name
+ DataType -> tyDataCtxt tycon_name
+ in
+ tcAddErrCtxt ctxt $
-- Lookup the pieces
tcLookupTyCon tycon_name `thenTc` \ (tycon_kind, _, rec_tycon) ->
tcConDecl tycon tyvars ctxt (ConDecl name ex_ctxt (NewCon ty) src_loc)
= tcAddSrcLoc src_loc $
tcHsType ty `thenTc` \ arg_ty ->
+ -- can't allow an unboxed type here, because we're effectively
+ -- going to remove the constructor while coercing it to a boxed type.
+ checkTc (not (isUnboxedType arg_ty)) (newTypeUnboxedField ty) `thenTc_`
let
data_con = mkDataCon (getName name)
[NotMarkedStrict]
fieldTypeMisMatch field_name
= sep [ptext SLIT("Declared types differ for field"), quotes (ppr field_name)]
+newTypeUnboxedField ty
+ = sep [ptext SLIT("Newtype constructor field has an unboxed type:"),
+ quotes (ppr ty)]
+
evalCtxt con eval_theta
= hsep [ptext SLIT("When checking the Eval context for constructor:"),
ppr con,