@@ -135,6 +135,8 @@ elabInstance info syn doc argDocs what fc cs n ps t expn ds = do
135 [PClause fc iname lhs [] rhs wb]]
135 [PClause fc iname lhs [] rhs wb]]
136 iLOG (show idecls)
136 iLOG (show idecls)
137 mapM_ (rec_elabDecl info EAll info) idecls
137 mapM_ (rec_elabDecl info EAll info) idecls
139+ checkInjectiveArgs fc n (class_determiners ci) (lookupTyExact iname (tt_ctxt ist))
138 addIBC (IBCInstance intInst n iname)
140 addIBC (IBCInstance intInst n iname)
@@ -276,3 +278,28 @@ elabInstance info syn doc argDocs what fc cs n ps t expn ds = do
276 clauseFor m iname ns (PClauses _ _ m' _)
278 clauseFor m iname ns (PClauses _ _ m' _)
277 = decorate ns iname m == decorate ns iname m'
279 = decorate ns iname m == decorate ns iname m'
278 clauseFor m iname ns _ = False
280 clauseFor m iname ns _ = False
282+checkInjectiveArgs :: FC -> Name -> [Int] -> Maybe Type -> Idris ()
283+checkInjectiveArgs fc n ds Nothing = return ()
284+checkInjectiveArgs fc n ds (Just ty)
285+ = do ist <- getIState
286+ let (_, args) = unApply (instantiateRetTy ty)
289+ ci i ist (a : as) | i `elem` ds
290+ = if isInj ist a then ci (i + 1) ist as
291+ else tclift $ tfail (At fc (InvalidTCArg n a))
292+ ci i ist (a : as) = ci (i + 1) ist as
293+ ci i ist [] = return ()
295+ isInj i (P Bound n _) = True
296+ isInj i (P _ n _) = isConName n (tt_ctxt i)
297+ isInj i (App f a) = isInj i f && isInj i a
298+ isInj i (V _) = True
299+ isInj i (Bind n b sc) = isInj i sc
302+ instantiateRetTy (Bind n (Pi _ _ _) sc)
303+ = substV (P Bound n Erased) (instantiateRetTy sc)
304+ instantiateRetTy t = t