@@ -140,7 +140,41 @@ runKindCheck = interpret $ \case
140140 either (handleErrClassDef modName classDef) pure $ I. runClassDefCheck ctx modName classDef
141141 where
142142 handleErrClassDef :: forall {b }. PC. ModuleName -> PC. ClassDef -> I. InferErr -> Eff effs b
143- handleErrClassDef _ _ _err = error " Throw an error"
143+ handleErrClassDef modName classDef = \ case
144+ I. InferUnboundTermErr ut ->
145+ case ut of
146+ QualifiedTyRef qtr -> do
147+ if qtr ^. qTyRef'moduleName == modName
148+ then do
149+ -- We're looking at the local module.
150+ let localRef = PC. LocalI . fst . withIso ltrISOqtr (\ _ f -> f) $ qtr
151+ let err = PC. UnboundTyRefError classDef localRef modName
152+ throwError . PC. CKC'ClassDefError $ err
153+ else do
154+ -- We're looking at a foreign module.
155+ let foreignRef = PC. ForeignI . withIso ftrISOqtr (\ _ f -> f) $ qtr
156+ throwError . PC. CKC'ClassDefError $ PC. UnboundTyRefError classDef foreignRef modName
157+ TyVar tv ->
158+ throwError . PC. CKC'ClassDefError $ PC. UnboundTyVarError classDef (PC. TyVar tv) modName
159+ QualifiedTyClassRef qcr ->
160+ if qcr ^. qTyClass'moduleName == modName
161+ then do
162+ -- We're looking at the local module.
163+ let localClassRef = PC. LocalCI . fst . withIso lcrISOqtcr (\ _ f -> f) $ qcr
164+ let err = PC. UnboundTyClassRefError classDef localClassRef modName
165+ throwError . PC. CKC'ClassDefError $ err
166+ else do
167+ -- We're looking at a foreign module.
168+ let foreignRef = PC. ForeignCI . withIso fcrISOqtcr (\ _ f -> f) $ qcr
169+ let err = PC. UnboundTyClassRefError classDef foreignRef modName
170+ throwError . PC. CKC'ClassDefError $ err
171+ I. InferUnifyTermErr (I. Constraint (k1, k2)) -> do
172+ err <- PC. IncorrectApplicationError classDef <$> kind2ProtoKind k1 <*> kind2ProtoKind k2 <*> pure modName
173+ throwError $ PC. CKC'ClassDefError err
174+ I. InferRecursiveSubstitutionErr _ ->
175+ throwError . PC. CKC'ClassDefError $ PC. RecursiveKindError classDef modName
176+ I. InferImpossibleErr t ->
177+ throwError $ PC. C'InternalError t
144178
145179 handleErrTyDef :: forall {b }. PC. ModuleName -> PC. TyDef -> I. InferErr -> Eff effs b
146180 handleErrTyDef modName td = \ case
0 commit comments